Principle underlying thread pool

Principle underlying thread pool

Manufacturers face questions:

1, you talk about the understanding of the volatile?

2, CAS Did you know?

3, ABA Atomic AtomicInteger class to talk about? Atomic update references know?

4, we all know that ArrayList is not thread-safe, please write an insecure coding case and gives the solution?

5, lock fair / unfair lock / reentrant lock / recursive lock / spin locks talk about your understanding? Please handwriting a spin lock.

6, CountDownLatch, CyclicBarrier, Semaphore used it?

7, blocking queue know?

8 , the thread pool used it? ThreadPoolExecutor talk about your understanding?

9, the thread pool used it? Production How do you set reasonable parameters?

10, location analysis and coding deadlock?

 

1, the principle underlying thread pool architecture diagram

2, the main processing flowchart thread pool

3, the main thread pool to explain the process flow ( important )

Task 1, after creating a thread pool, waiting for requests submitted over.

2, when you call the execute () method to add a task request, the thread pool will do the following judgment:

       2.1 If the number of threads running less than corePoolSize, then immediately create a thread to run this task;

       2.2 If the number of running threads is greater than or equal to corePoolSize, then the task will be placed in the queue;

       2.3 If this time the queue is full and the number of threads running also less than maximumPoolSize, you still have to create a non-core threads running this task;

       2.4 If the queue is full and the number of threads is greater than or equal to maximumPoolSize, then the policy will start to refuse to perform saturation.

3, when a thread is completed, it is removed from a queue task is performed.

4, when a thread is nothing, and over a certain period of time (keepAliveTime), thread pool will determine:

       If the number of the currently running thread is more than corePoolSize, then the thread will be stopped.

       So after all the tasks of the thread pool is completed, it will eventually shrink to the size of corePoolSize.

Guess you like

Origin blog.csdn.net/longgeqiaojie304/article/details/93475854