Java ThreadPoolExecutor and BlockingQueue to use

The Oracle site ( http://docs.oracle.com/javase/7/docs/api/?java/util/concurrent/ThreadPoolExecutor.html ) in the Queuing section says that "If corePoolSize or more threads are running, the Contractor always prefers the order of the request, not adding a new thread. "

In our code, corePoolSize is 1, and maximumPoolSize is 10 or 20. (1) Is this bad practice? or rather, not the best way to use ThreadPool? (2) Have you recommended that corePoolSize and maximumPoolSize be the same when creating ThreadPoolExecutor?

Another question regarding using BlockingQueue when creating ThreadPoolExecutor - between LinkedBlockingQueue or ConcurrentLinkedQueue? Have I looked more from lock point and performance? Although checking the test proves, inserting into concurrentLinkedQueue is pretty fast compared to others. Any thoughts?

Edited by:

The first part was answered in different questions. The one I liked How to get ThreadPoolExecutor to increase threads to max before the queue?

+4
source share
2 answers

Please find the following items.

  • ​​ , corePoolSize, . corePoolSize .

  • , corePoolSize , , maximumPoolSize.

  • , corePoolSize , , , KeepAliveTime.

  • ​​ , corePoolSize, , maximumPoolSize , , . , corePoolSize , keepAliveTime .

  • corePoolSize maximumPoolSize ,

    ThreadPool

    - 1.

    - 10 20.

1: ? , , ThreadPool?

, .

, , . . , .

2: corePoolSize maximumPoolSize ThreadPoolExecutor?

. , . , .

3 concurrentLinkedQueue vs LinkedBlockingQueue

concurrentLinkedQueue, threadpool BlockingQueue. concurrentLinkedBlockingQueue. concurrentLinkedBlockingQueue . LinkedBlockingQueue .

+1

, , , TPE (Runnable) , , . Runnables. .

, , .

0

Source: https://habr.com/ru/post/1533125/


All Articles