Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved implementation using Executors

  • Loading branch information...
commit 41e5c7ed5f82b5a588828584c3ac765b40a76cea 1 parent d48bf97
@Tibor17 authored
Showing with 11 additions and 19 deletions.
  1. +11 −19 src/main/java/org/junit/experimental/ParallelComputer.java
View
30 src/main/java/org/junit/experimental/ParallelComputer.java
@@ -32,30 +32,22 @@ public static Computer methods() {
return new ParallelComputer(false, true);
}
- private static <T> Runner parallelize(Runner runner) {
- if (runner instanceof ParentRunner<?>) {
+ private static Runner parallelize(Runner runner) {
+ if (runner instanceof ParentRunner) {
((ParentRunner<?>) runner).setScheduler(new RunnerScheduler() {
- private final List<Future<Object>> fResults= new ArrayList<Future<Object>>();
+ private final ExecutorService fService= Executors.newCachedThreadPool();
- private final ExecutorService fService= Executors
- .newCachedThreadPool();
-
- public void schedule(final Runnable childStatement) {
- fResults.add(fService.submit(new Callable<Object>() {
- public Object call() throws Exception {
- childStatement.run();
- return null;
- }
- }));
+ public void schedule(Runnable childStatement) {
+ fService.submit(childStatement);
}
public void finished() {
- for (Future<Object> each : fResults)
- try {
- each.get();
- } catch (Exception e) {
- e.printStackTrace();
- }
+ try {
+ fService.shutdown();
+ fService.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
+ } catch (InterruptedException e) {
+ e.printStackTrace(System.err);
+ }
}
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.