java.util.concurrent and tools

1. The main sections of the java.util.concurrent system include content

When it comes to JUC, it actually means Java's multi-threading and locks, some state transitions, interrupts, etc. It also involves some tools, as shown in the figure below:

Tools also contains 5 parts of knowledge: Executors, Semaphor, Exchanger, CyclicBarrier, CountDownLatch, which are actually five tool classes

 

 

 

二、Executors

It is mainly used to create thread pools, proxying the creation of thread pools, making your creation entry parameters simple. You can know what kind of thread pool you want to create through the method name, and what kind of function it is. , In fact, the thread pool is implemented in a unified way, through the construction method overloading, so that different functions can be realized, but often this way often does not know the meaning of the specific entry parameter changes, unless you read the source code. At this time, it is done in the way of builder mode, and it can tell you what the builder does.

 

Common methods are (all are static methods):

 

1. Create a thread pool of a specified size. If it exceeds the size, put it into the blocken queue. The default is LinkedBlockingQueue. The default ThreadFactory is: Executors.defaultThreadFactory(), which is an internal class of Executors.

 

Executors.newFixedThreadPool(int)

The internal implementation is as follows:

public static ExecutorService newFixedThreadPool(int nThreads) { 

    return new ThreadPoolExecutor(nThreads, nThrea

Guess you like

Origin blog.csdn.net/hongweideng/article/details/104385259