Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ExecutorService  RSS feed

 
manu chaox
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!