Is there a default thread pool in java

I can create a new threadpool in java and execute tasks on it using ExecutorService.newFixedThreadPool and Methods ExecutorService.submit .

Is there a default thread pool that I can reuse for all executing services in my java program? Or do I just need to create a singleton containing the default thread pool? C # has a default thread pool that launches tasks when the Task.Factory.StartNew method is called .

+4
source share
2 answers

Using separate thread pools is good, the default practice and sharing of threads is (possibly premature) optimization.

Through Java 7, the answer is no, there is no default thread, and the recommendation is to have many threads. This is a good separation and will prevent blocking the behavior of one set of tasks from interfering with another.

If you share file paths, you should ask questions such as:

  • Can a logging system distinguish between tasks? (Threads are one way to distinguish.)
  • If task pool A accidentally requests too many threads and shuts down, should pool B start? When you notice that task pool B is not working, can you diagnose the problem in task pool A?
  • Should block A pools have to starve B?

, LightweightThreadpool. 5 , , . 6- ... , , , , , . 5 , , , , , , , , .

, , , . , . , , .

Java 8, "" ( Tagir ). , , .

+5

Java-8 ForkJoinPool.commonPool(), , . , Arrays.parallelSort() Stream API. , CompletableFuture, CompletableFuture.supplyAsync().

+9

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


All Articles