Skip to content

Commit

Permalink
avoids reusing Executor's Thread instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Tibor Digana committed Sep 21, 2012
1 parent 24cbcbc commit 7602636
Showing 1 changed file with 15 additions and 5 deletions.
Expand Up @@ -10,28 +10,38 @@
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.Before;
import org.junit.BeforeClass;
import java.util.concurrent.CountDownLatch;

public class ParallelMethodTest {
private static volatile Thread fOne= null;
private static volatile Thread fTwo= null;

public static class Example {
@Test public void one() {
private static volatile CountDownLatch fSynchronizer;

@BeforeClass public static void init() {
fSynchronizer= new CountDownLatch(2);
}
@Test public void one() throws InterruptedException {
fSynchronizer.countDown();
fSynchronizer.await();
fOne= Thread.currentThread();
}
@Test public void two() {
@Test public void two() throws InterruptedException {
fSynchronizer.countDown();
fSynchronizer.await();
fTwo= Thread.currentThread();
}
}

@Before public void cleanupReferences() {
@Before public void init() {
fOne= null;
fTwo= null;
}

@Test public void testsRunInParallel() {
Result result= JUnitCore.runClasses(ParallelComputer.methods(),
Example.class);
Result result= JUnitCore.runClasses(ParallelComputer.methods(), Example.class);
assertTrue(result.wasSuccessful());
assertNotNull(fOne);
assertNotNull(fTwo);
Expand Down

0 comments on commit 7602636

Please sign in to comment.