Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make ClassRequest memoize the runner.

Creating the runner can be an expensive operation. Other types of requests
are written in such a way that the runner is already memoized.
  • Loading branch information...
commit 41540137ced4df4aaf0cee69ca43f5d95503c21d 1 parent ce0195c
@kcooney kcooney authored
Showing with 9 additions and 3 deletions.
  1. +9 −3 src/main/java/org/junit/internal/requests/ClassRequest.java
View
12 src/main/java/org/junit/internal/requests/ClassRequest.java
@@ -6,9 +6,10 @@
import org.junit.runner.Runner;
public class ClassRequest extends Request {
+ private final Object fRunnerLock = new Object();
private final Class<?> fTestClass;
-
- private boolean fCanUseSuiteMethod;
+ private final boolean fCanUseSuiteMethod;
+ private Runner fRunner;
public ClassRequest(Class<?> testClass, boolean canUseSuiteMethod) {
fTestClass= testClass;
@@ -21,6 +22,11 @@ public ClassRequest(Class<?> testClass) {
@Override
public Runner getRunner() {
- return new AllDefaultPossibilitiesBuilder(fCanUseSuiteMethod).safeRunnerForClass(fTestClass);
+ synchronized (fRunnerLock) {
+ if (fRunner == null) {
+ fRunner = new AllDefaultPossibilitiesBuilder(fCanUseSuiteMethod).safeRunnerForClass(fTestClass);
+ }
+ return fRunner;
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.