code: public static void main(String[] args)
      {
          Context cx = Context.enter();
          try {
              // Precompile source only once
              String source = ""
                              +"var x = 'sharedScope';\n"
                              +"function f() { return x; }\n"
                              // Dynamic scope works with nested function too
                              +"function initClosure(prefix) {\n"
                              +"    return function test() { return prefix+x; }\n"
                              +"}\n"
                              +"var closure = initClosure('nested:');\n"
                              +"";
              Script script = cx.compileString(source, "sharedScript", 1, null);
  
              useDynamicScope = false;
              runScripts(cx, script);
              useDynamicScope = true;
              runScripts(cx, script);
          } finally {
              Context.exit();
          }
      }
docs: Main entry point.
  
  Set up the shared scope and then spawn new threads that execute
  relative to that shared scope. Try to run functions with and
  without dynamic scope to see the effect.
  
  The expected output is
  <pre>
  sharedScope
  nested:sharedScope
  sharedScope
  nested:sharedScope
  sharedScope
  nested:sharedScope
  thread0
  nested:thread0
  thread1
  nested:thread1
  thread2
  nested:thread2
  </pre>
  The final three lines may be permuted in any order depending on
  thread scheduling.