Are the threads generated by 2 separate executor services in different threads guaranteed to be different?

StackOverflow https://stackoverflow.com/questions/22622894

سؤال

Lets say I have 2 different threads running concurrently. Each thread spins up a cached thread pool executor service that spins a bunch more threads. Will each pool have their own distinct set of threads? Or is there a possibility for threads to be shared between them?

هل كانت مفيدة؟

المحلول

Will each pool have their own distinct set of threads? Or is there a possibility for threads to be shared between them?

Each pool has control over its own threads -- when to create new ones, when to destroy them etc. No two ThreadPools will ever "see" one another's threads.

In other words: there is no "giant pool" at the JVM level from which ExecutorServices, or ScheduledExecutorServices or even ForkJoinPools would pick from. Were it the case, the maintenance cost would be prohibitive...

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top