Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make ClassRequest memoize the runner. #412

Merged
merged 1 commit into from

2 participants

@kcooney
Collaborator

Creating the runner can be an expensive operation. Other types of requests
are written in such a way that the runner is already memoized.

@kcooney kcooney 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.
4154013
@dsaff dsaff merged commit 34d2943 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 3, 2012
  1. @kcooney

    Make ClassRequest memoize the runner.

    kcooney authored
    Creating the runner can be an expensive operation. Other types of requests
    are written in such a way that the runner is already memoized.
This page is out of date. Refresh to see the latest.
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;
+ }
}
}
Something went wrong with that request. Please try again.