Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: markspace Newsgroups: comp.lang.java.programmer Subject: Re: Threads, waiting for last one to finish Date: Fri, 11 Jan 2013 14:05:10 -0800 Organization: A noiseless patient Spider Lines: 17 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 11 Jan 2013 22:05:13 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="61282af8d6595e8d991edb5ac03d6e00"; logging-data="22680"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199x2yQZ5lPy2pv4w6UfVADXTZY/CYPiNk=" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 In-Reply-To: Cancel-Lock: sha1:wpCLtsSbtkgIavWV/MkCeTITKE4= Xref: csiph.com comp.lang.java.programmer:21340 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. > The Executors class has convenience methods to make thread pools easier to use. ExecutorService es = Executors.newFixedThreadPool( 25 ); // submit jobs here es.shutdown(); The shutdown() will wait for all jobs to finish. I don't think you can get easier than that. It's two lines of code!