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 e48f6d4 commit 623bd92
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,47 @@
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.Before;
import java.util.concurrent.CountDownLatch;


public class ParallelClassTest {
private static volatile Thread fExample1One= null;
private static volatile Thread fExample1Two= null;
private static volatile Thread fExample2One= null;
private static volatile Thread fExample2Two= null;
private static volatile CountDownLatch fSynchronizer;

public static class Example1 {
@Test public void one() {
@Test public void one() throws InterruptedException {
fSynchronizer.countDown();
fSynchronizer.await();
fExample1One= Thread.currentThread();
}
@Test public void two() {
@Test public void two() throws InterruptedException {
fSynchronizer.countDown();
fSynchronizer.await();
fExample1Two= Thread.currentThread();
}
}
public static class Example2 {
@Test public void one() {
@Test public void one() throws InterruptedException {
fSynchronizer.countDown();
fSynchronizer.await();
fExample2One= Thread.currentThread();
}
@Test public void two() {
@Test public void two() throws InterruptedException {
fSynchronizer.countDown();
fSynchronizer.await();
fExample2Two= Thread.currentThread();
}
}

@Before public void cleanupReferences() {
@Before public void init() {
fExample1One= null;
fExample1Two= null;
fExample2One= null;
fExample2Two= null;
fSynchronizer= new CountDownLatch(2);
}

@Test public void testsRunInParallel() {
Expand Down

0 comments on commit 623bd92

Please sign in to comment.