Larger thread or optional ExecutorService when a new thread view starts?

I have a question regarding possible overhead ExecutorServicein Java.

In the current implementation there is ExecutorService Aa capacity of 5 threads.

  • It launches type threads A.
  • Type Astreams read and write the database.

Now the type stream Bwill be started after the completion of some type streams A.

  • The number of threads Bthat will be launched is different from time to time.
  • type Bstreams run some file I / O system (rather than a database).

So i have to

  • add new ExecutorServiceto handle threadsB
  • or should I increase the capacity ExecutorService Aand start the Bthread type with this too?

I think that for Java there may be additional overhead to have two ExecutorServices, but on the other hand, the total number of threads will increase anyway. Does it matter at all?

+3
source share
2 answers

I will recommend two ExecutorServices, then you can use the different ones ExecutorServiceprovided by the package java.util.concurrent.

This simplifies the code, and overhead is ignored.

  • ExecutorService a with a fixed pool of threads set to five threads.
  • ExecutorService b with a pool of cached streams.
+4
source

5 , , , , , ,

+1

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


All Articles