Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Threads, waiting for last one to finish Date: Sun, 13 Jan 2013 19:38:44 +0100 Lines: 33 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net WFoPOnqsWI+ZtyZHfljV/gSZjq22A/xG9yEgpe3nke9Lg+QdQuBfd8iktcxjBNnHM= Cancel-Lock: sha1:VZAVvzHZMmEOmQhyaI9sBSlvhV4= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:21381 On 12.01.2013 06:19, Knute Johnson wrote: > On 1/11/2013 1:56 PM, Roedy Green wrote: >> I have 25 threads that start at once. I need to wait until the last >> one completes. Is there a better way to handle that than using a >> ThreadPoolExecutor which seems overkill. >> > > You can always join() them. I am surprised that this got just one mention so far. In absence of Executor (which has some issues, as has been mentioned) this is the most straightforward way to do it. // untested and from memory final Thread[] threads = new Thread[15]; for ( int i = 0; i < threads.length; ++i ) { final Thread th = new Thread(...); th.start(); threads[i] = th; } for ( final Thread th : threads ) { th.join(); } Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/