Thread concurrency library

From the beginning JDK1.5 some concurrency library, to the management and use of JAVA thread provides a powerful convenience.

java.util.current package provides a thread optimization of operations management, making use of threads becomes handy,

This package provides a running thread, create a thread pool thread of control lifecycle.

 

java provided by Executors four static methods to create a thread pool, namely:

  newCachedThreadPool create a cache thread pool, thread pool longer than if treatment needs, the flexibility to reclaim idle thread, if not recyclable, the new thread

  newFixedThreadPool create a fixed-size thread pool, you can control the maximum number of concurrent threads, excess threads will wait in the queue.

  newScheduledThreadPool create a fixed-size thread pool to support regular and periodic task execution.

  new SingleThreadExcutor create a single-threaded thread pool, use it only to perform the task only worker threads to ensure that all tasks are performed in a specified order

 

Thread pool functions:

1. The number of the thread pool is defined, it does not cause the thread lead due to excessive slowness or system crashes

2. The thread pool does not need

Guess you like

Origin www.cnblogs.com/gxlaqj/p/11311291.html