• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ExecutorService

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I'm thinking about a new battle cry. Maybe "Not in the face! Not in the face!" Any thoughts tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic