Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Threads, waiting for last one to finish

Reply
Thread Tools

Threads, waiting for last one to finish

 
 
Robert Klemme
Guest
Posts: n/a
 
      01-20-2013
On 16.01.2013 10:28, Kevin McMurtrie wrote:

> Fixed size pools have some problems too but they're less frequent and
> unobtrusive. You'd probably never hit them unless you're using
> shutdown() rather than Future.get() to wait for task completion.


I was going to add that most of the issues of the implementation we are
talking about stem from the fact that the number of active threads is
adjusted all the time, i.e. threads are created and die (or at least
that was the intention) all the time.

For most real world problems I am aware of it is sufficient to create
all threads upfront and let them block waiting for work. You are
expecting to use them anyway at some point in time (that's why you set a
specific max) so at least when load is highest the biggest number of
threads is active anyway. Other resources (memory) have to be adjusted
to that fact anyway and if the pool is idle there will be enough memory
to keep those blocking threads around.

The only other scheme that seems to be reasonable to me is to create
threads on demand and never let them die before pool shutdown. That
would at least ensure low overhead for low load situations. But even
this scheme has some overhead in terms of locking already.

My preferred way for shutdown of thread pools is a stop element of which
as many instances as threads around are inserted into the queue. Every
worker threads which reads it terminates itself. That way you do not
need any additional locking and just join all active threads before you
let the shutdown method return. The details of proper shutdown are
still tricky because one can introduce a number of nasty race conditions
which will leave unprocessed items in the queue.

There are many applications though where production of work for the pool
is stopped before the pool is shut down so shutdown race conditions are
not an issues for those types of applications.

Kind regards

robert


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      01-26-2013
On 25.01.2013 20:46, Wanja Gayk wrote:
> In article <50f264aa$0$80119$(E-Mail Removed)>, Kevin McMurtrie
> ((E-Mail Removed)) says...
>
>> The Executor classes are horribly buggy. Pool size adjustment, idle
>> timeouts, and shutdown sequences do NOT work. Some of the features are
>> impossible to implement efficiently so Sun instead chose to implement
>> them incorrectly.

>
> Could be more specific?


See his reply from January 16. in this thread.

Kind regards

robert


--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
waiting for multiple child processes to finish Martin DeMello Ruby 1 11-13-2006 02:30 PM
Print digital photos online - 9 cents per print, plus 10% off. All sizes from 4x6 up to 30x60. Same price for Matte finish and glossy finish nathan_usny Digital Photography 2 09-12-2005 11:30 PM
Print digital photos online - 9 cents per print, plus 10% off. All sizes from 4x6 up to 30x60. Same price for Matte finish and glossy finish nathan_usny Digital Photography 0 09-12-2005 06:09 PM
waiting for external process to finish (using Runtime and Thread classes) brownjenkn@aol.com Java 1 04-22-2005 07:55 PM
Waiting for processes to finish under Solaris Behrang Dadsetan Python 1 07-15-2003 07:56 PM



Advertisments