Forums Register Login

ExecutorService

+Pie Number of slices to send: Send
Hi,
I tried this usage example :
http://java.sun.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html

Now, I'd like to do this:

poolSize=3 for 0-2 Worker Threads
poolSize=6 for 3-5 Worker Threads
...


If count of workerThreads is decreased then adjust poolSize.


Could you give me any idea?
+Pie Number of slices to send: Send
Looking at Executors I don't see a creation method for one with min and max threads. I've used CachedThreadPool which will grow without bounds and destroy threads after some idle time. I guess you could look at the various pool implementations and write your own with min and max.

What's wrong with the variations that are there? A fixed pool has a max; some of them might go idle but how bad is that when they're not running?
+Pie Number of slices to send: Send
You might try ThreadPoolExecutor, which allows you to specify a minimum and maximum number of threads. I can't really see why you might want more than that, but if you do, you could probably extend ThreadPoolExecutor to add more complex behavior, changing the min and max values in response to changing circumtances.
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1066 times.
Similar Threads
running a fixed number of threads all the time
Thread.sleep(3600000) is = minute ?
Protecting for loop values
Share data between threads
killing a Thread ?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 20:11:57.