Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #21584

Re: Threads, waiting for last one to finish

From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: Threads, waiting for last one to finish
Date 2013-01-20 15:21 +0100
Message-ID <am2cr3FhaqcU1@mid.individual.net> (permalink)
References (2 earlier) <50f264aa$0$80119$742ec2ed@news.sonic.net> <50f37d14$0$293$14726298@news.sunsite.dk> <50f4f730$0$80137$742ec2ed@news.sonic.net> <kd3vjc$cat$1@dont-email.me> <50f672b6$0$80156$742ec2ed@news.sonic.net>

Show all headers | View raw


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/

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Threads, waiting for last one to finish Roedy Green <see_website@mindprod.com.invalid> - 2013-01-11 13:56 -0800
  Re: Threads, waiting for last one to finish markspace <markspace@nospam.nospam> - 2013-01-11 14:05 -0800
    Re: Threads, waiting for last one to finish Roedy Green <see_website@mindprod.com.invalid> - 2013-01-11 14:14 -0800
      Re: Threads, waiting for last one to finish markspace <markspace@nospam.nospam> - 2013-01-11 15:11 -0800
        Re: Threads, waiting for last one to finish Arne Vajhøj <arne@vajhoej.dk> - 2013-01-11 20:02 -0500
        Re: Threads, waiting for last one to finish Roedy Green <see_website@mindprod.com.invalid> - 2013-01-12 01:51 -0800
        Re: Threads, waiting for last one to finish Roedy Green <see_website@mindprod.com.invalid> - 2013-01-12 02:20 -0800
          Re: Threads, waiting for last one to finish Arne Vajhøj <arne@vajhoej.dk> - 2013-01-12 09:08 -0500
        Re: Threads, waiting for last one to finish Roedy Green <see_website@mindprod.com.invalid> - 2013-01-12 10:36 -0800
          Re: Threads, waiting for last one to finish Arne Vajhøj <arne@vajhoej.dk> - 2013-01-12 16:17 -0500
    Re: Threads, waiting for last one to finish Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-01-12 23:39 -0800
      Re: Threads, waiting for last one to finish Arne Vajhøj <arne@vajhoej.dk> - 2013-01-13 22:35 -0500
        Re: Threads, waiting for last one to finish Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-01-14 09:12 -0800
        Re: Threads, waiting for last one to finish Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-01-14 22:29 -0800
          Re: Threads, waiting for last one to finish markspace <markspace@nospam.nospam> - 2013-01-15 08:19 -0800
            Re: Threads, waiting for last one to finish Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-01-16 01:28 -0800
              Re: Threads, waiting for last one to finish Robert Klemme <shortcutter@googlemail.com> - 2013-01-20 15:21 +0100
            Re: Threads, waiting for last one to finish Kevin McMurtrie <mcmurtrie@pixelmemory.us> - 2013-01-18 21:58 -0800
      Re: Threads, waiting for last one to finish Robert Klemme <shortcutter@googlemail.com> - 2013-01-26 17:20 +0100
  Re: Threads, waiting for last one to finish Knute Johnson <nospam@knutejohnson.com> - 2013-01-11 21:19 -0800
    Re: Threads, waiting for last one to finish Robert Klemme <shortcutter@googlemail.com> - 2013-01-13 19:38 +0100
      Re: Threads, waiting for last one to finish Knute Johnson <nospam@knutejohnson.com> - 2013-01-14 08:58 -0800
      Re: Threads, waiting for last one to finish Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-01-15 05:05 -0400
  Re: Threads, waiting for last one to finish Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-01-12 08:42 -0400
    Re: Threads, waiting for last one to finish Roedy Green <see_website@mindprod.com.invalid> - 2013-01-12 23:56 -0800
      Re: Threads, waiting for last one to finish Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-01-13 10:53 -0400
        Re: Threads, waiting for last one to finish Roedy Green <see_website@mindprod.com.invalid> - 2013-01-13 19:18 -0800
          Re: Threads, waiting for last one to finish Arne Vajhøj <arne@vajhoej.dk> - 2013-01-13 22:26 -0500
            Re: Threads, waiting for last one to finish Arved Sandstrom <asandstrom2@eastlink.ca> - 2013-01-14 05:51 -0400
              Re: Threads, waiting for last one to finish Arne Vajhøj <arne@vajhoej.dk> - 2013-01-14 19:02 -0500
        Re: Threads, waiting for last one to finish Roedy Green <see_website@mindprod.com.invalid> - 2013-01-13 19:43 -0800
  Re: Threads, waiting for last one to finish Sebastian <news@seyweiler.dyndns.org> - 2013-01-13 15:19 +0100

csiph-web