Lazy initialization of the JavaScript runner to prevent needless compilation of the VM
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 06 Feb 2013 13:30:31 +0100
changeset 68193196a859fc5
parent 668 b4354a30d4dd
child 683 327a6da275d6
child 689 f87c33d2fa7b
child 693 92b628f99997
Lazy initialization of the JavaScript runner to prevent needless compilation of the VM
vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java
     1.1 --- a/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java	Tue Feb 05 10:19:10 2013 +0100
     1.2 +++ b/vmtest/src/main/java/org/apidesign/bck2brwsr/vmtest/impl/LaunchSetup.java	Wed Feb 06 13:30:31 2013 +0100
     1.3 @@ -31,13 +31,19 @@
     1.4  public final class LaunchSetup {
     1.5      static LaunchSetup INSTANCE = new LaunchSetup();
     1.6      
     1.7 -    private final Launcher js = Launcher.createJavaScript();
     1.8 +    private Launcher js;
     1.9      private final Map<String,Launcher> brwsrs = new LinkedHashMap<>();
    1.10      
    1.11      private LaunchSetup() {
    1.12      }
    1.13      
    1.14 -    public  Launcher javaScript() {
    1.15 +    public Launcher javaScript() {
    1.16 +        return js(true);
    1.17 +    } 
    1.18 +    private synchronized  Launcher js(boolean create) {
    1.19 +        if (js == null && create) {
    1.20 +            js = Launcher.createJavaScript();
    1.21 +        }
    1.22          return js;
    1.23      } 
    1.24      
    1.25 @@ -52,7 +58,9 @@
    1.26  
    1.27      @BeforeGroups("run")
    1.28      public void initializeLauncher() throws IOException {
    1.29 -        js.initialize();
    1.30 +        if (js(false) != null) {
    1.31 +            js(true).initialize();
    1.32 +        }
    1.33          for (Launcher launcher : brwsrs.values()) {
    1.34              launcher.initialize();
    1.35          }
    1.36 @@ -60,7 +68,9 @@
    1.37  
    1.38      @AfterGroups("run")
    1.39      public void shutDownLauncher() throws IOException, InterruptedException {
    1.40 -        js.shutdown();
    1.41 +        if (js(false) != null) {
    1.42 +            js(true).shutdown();
    1.43 +        }
    1.44          for (Launcher launcher : brwsrs.values()) {
    1.45              launcher.shutdown();
    1.46          }