简体   繁体   中英

Concurrent ThreadPoolExecutor.submit() calls

I have a ThreadPoolExecutor whose submit method may be called concurrently by multiple threads. I'm wondering how the ThreadPoolExecutor would handle this. I don't see that submit is atomic from the source code, although maybe I'm missing something. Thanks in advance for any advice.

At submit() ExecutorService relies on its BlockingQueue for synchronization.

When initializing a executor you have to provide a queue instance which is used to store all submited tasks and is used as source for the thread pool to read from.

For executors initialized from one of the Executors fixed size factory methods a LinkedBlockingQueue is used internally.

LinkedBlockingQueue internally uses a ReentrantLock to lock and synchronize when it is offered new entries to store

As long as you work with java.util.concurrent implementations for your Queue concurrent submits should work just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM