You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by th...@apache.org on 2011/11/08 11:16:24 UTC
svn commit: r1199174 -
/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java
Author: thomasm
Date: Tue Nov 8 10:16:24 2011
New Revision: 1199174
URL: http://svn.apache.org/viewvc?rev=1199174&view=rev
Log:
Slightly improved concurrency test helper.
Modified:
jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java
Modified: jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java?rev=1199174&r1=1199173&r2=1199174&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java (original)
+++ jackrabbit/sandbox/microkernel/src/test/java/org/apache/jackrabbit/mk/util/Concurrent.java Tue Nov 8 10:16:24 2011
@@ -35,16 +35,19 @@ public class Concurrent {
run(task, 2, 1000);
}
- private static void run(final Task task, int threadCount, int millis) throws Exception {
+ public static void run(final Task task, int threadCount, int millis) throws Exception {
final AtomicBoolean stopped = new AtomicBoolean();
- final AtomicReference<Exception> exception = new AtomicReference<Exception>();
+ final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
ArrayList<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < threadCount; i++) {
- Thread t = new Thread("Test") {
+ Thread t = new Thread("Task " + i) {
public void run() {
while (!stopped.get()) {
try {
task.call();
+ } catch (Error e) {
+ exception.set(e);
+ stopped.set(true);
} catch (Exception e) {
exception.set(e);
stopped.set(true);
@@ -55,7 +58,7 @@ public class Concurrent {
t.start();
threads.add(t);
}
- Exception e = null;
+ Throwable e = null;
while (e == null && millis > 0) {
Thread.sleep(10);
millis -= 10;
@@ -66,7 +69,10 @@ public class Concurrent {
t.join();
}
if (e != null) {
- throw e;
+ if (e instanceof Exception) {
+ throw (Exception) e;
+ }
+ throw (Error) e;
}
}