Forums Register Login

Java concurrency

+Pie Number of slices to send: Send
If I were to create an executor with a thread pool. Is that thread pool available to the whole application or is a new one instanciated per each method call or class instanciation?
+Pie Number of slices to send: Send
It depends where you put the code that starts the thread pool, and where you store the reference to that pool. If you use a static variable and static initializer, then the entire application is using the same thread pool. If it's an instance variable initialized in a constructor, then each instance has a different pool. If you use a local variable in a method, then you get a new pool each time you call the method. (This last seems pretty pointless in general, though there may be a few cases where it makes sense.)
+Pie Number of slices to send: Send
It makes sense in the run() method of a thread that runs for the life of the application
They worship nothing. They say it's because nothing lasts forever. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 752 times.
Similar Threads
Thread pool
Process the multiple records in a file by Producer/consumer concept using Multithreading
Thread pool
Thread pool in
What is the use of thread pool in weblogic?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:38:28.