Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Daniele Futtorovic Newsgroups: comp.lang.java.gui Subject: Re: Synchronization when collecting data from the EDT? Date: Fri, 10 Jun 2011 05:22:52 +0200 Organization: A noiseless patient Spider Lines: 34 Message-ID: References: <8jPGp.40014$Vp.14760@newsfe14.iad> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Injection-Date: Fri, 10 Jun 2011 03:22:50 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="lTR3Vq3EMfgRaqqjRT8Q2w"; logging-data="20109"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/517JTkI8gulkxy4QCR20s" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 In-Reply-To: Cancel-Lock: sha1:fSc6TpEJVkDYh2CqwljhNB3K3Fc= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.gui:4597 On 10/06/2011 01:17, Daniele Futtorovic allegedly wrote: > static void invokeAndWait( final Runnable ron, long timeout, TimeUnit unit ) > throws InterruptedException > { > final CountDownLatch l = new CountDownLatch(1); > EventQueue.invokeLater( > new Runnable(){ @Override public void run() { > ron.run(); > l.countDown(); > }} > ); > > l.await( timeout, unit ); > } Sigh. Same mistake here. static void invokeAndWait( final Runnable ron, long timeout, TimeUnit unit ) throws InterruptedException { final CountDownLatch l = new CountDownLatch(1); EventQueue.invokeLater( new Runnable(){ @Override public void run() { try { ron.run(); } finally { l.countDown(); } }} ); l.await( timeout, unit ); }