org.sonatype.aether.util.concurrency
Class RunnableErrorForwarder

java.lang.Object
  extended by org.sonatype.aether.util.concurrency.RunnableErrorForwarder

public class RunnableErrorForwarder
extends Object

A utility class to forward any uncaught Error or RuntimeException from a Runnable executed in a worker thread back to the parent thread. The simplified usage pattern looks like this:

 RunnableErrorForwarder errorForwarder = new RunnableErrorForwarder();
 for ( Runnable task : tasks )
 {
     executor.execute( errorForwarder.wrap( task ) );
 }
 errorForwarder.await();
 

Author:
Benjamin Bentmann

Constructor Summary
RunnableErrorForwarder()
           
 
Method Summary
 void await()
          Causes the current thread to wait until all previously wrapped runnables have terminated and potentially re-throws an uncaught RuntimeException or Error from any of the runnables.
 Runnable wrap(Runnable runnable)
          Wraps the specified runnable into an equivalent runnable that will allow forwarding of uncaught errors.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RunnableErrorForwarder

public RunnableErrorForwarder()
Method Detail

wrap

public Runnable wrap(Runnable runnable)
Wraps the specified runnable into an equivalent runnable that will allow forwarding of uncaught errors.

Parameters:
runnable - The runnable from which to forward errors, must not be null.
Returns:
The error-forwarding runnable to eventually execute, never null.

await

public void await()
Causes the current thread to wait until all previously wrapped runnables have terminated and potentially re-throws an uncaught RuntimeException or Error from any of the runnables. In case multiple runnables encountered uncaught errors, one error is arbitrarily selected.



Copyright © 2010-2011 Sonatype, Inc.. All Rights Reserved.