From 93d627333b8d7b4b97f53fd05d94b9c1217eb7fc Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Fri, 23 Dec 2011 13:37:21 +0100 Subject: [PATCH] Improved error checking and docs --- .../util/concurrency/RunnableErrorForwarder.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/aether-util/src/main/java/org/eclipse/aether/util/concurrency/RunnableErrorForwarder.java b/aether-util/src/main/java/org/eclipse/aether/util/concurrency/RunnableErrorForwarder.java index d0e1585f..8144f9a0 100644 --- a/aether-util/src/main/java/org/eclipse/aether/util/concurrency/RunnableErrorForwarder.java +++ b/aether-util/src/main/java/org/eclipse/aether/util/concurrency/RunnableErrorForwarder.java @@ -36,6 +36,13 @@ public final class RunnableErrorForwarder private final AtomicReference error = new AtomicReference(); + /** + * Creates a new error forwarder for worker threads spawned by the current thread. + */ + public RunnableErrorForwarder() + { + } + /** * Wraps the specified runnable into an equivalent runnable that will allow forwarding of uncaught errors. * @@ -81,7 +88,8 @@ public final class RunnableErrorForwarder /** * Causes the current thread to wait until all previously {@link #wrap(Runnable) wrapped} runnables have terminated * and potentially re-throws an uncaught {@link RuntimeException} or {@link Error} from any of the runnables. In - * case multiple runnables encountered uncaught errors, one error is arbitrarily selected. + * case multiple runnables encountered uncaught errors, one error is arbitrarily selected. Note: This + * method must be called from the same thread that created this error forwarder instance. */ public void await() { @@ -108,6 +116,12 @@ public final class RunnableErrorForwarder private void awaitTerminationOfAllRunnables() { + if ( !thread.equals( Thread.currentThread() ) ) + { + throw new IllegalStateException( "wrong caller thread, expected " + thread + " and not " + + Thread.currentThread() ); + } + boolean interrupted = false; while ( counter.get() > 0 ) -- GitLab