Closed gtskaushik closed 3 years ago
@mxro If the proposed fix is fine, I can create a PR for the same
@gtskaushik Thank you for reporting this issue and documenting the issue very well!
Yes I think this will be a great way forward to make the library more thread safe. Please be welcome to prepare a PR š
@mxro Created a PR - https://github.com/javadelight/delight-rhino-sandbox/pull/19
Can you confirm this is now all fixed and close the issue if that is the case? Thank you!
It is working now. Closing the issue
Using a singleton RhinoSandbox object
Using a RhinoSandbox object per Thread (RhinoSandbox is kept in a ThreadLocal). This is to mitigate the race condition problem
Test Case
The above code is expected to fail with ScriptDuration Exception but doesn't. But if we start Thread 2 first, we get the expected exception
Proposal
SafeContext.makeContext should use org.mozilla.javascript.Context(ContextFactory factory) instead of org.mozilla.javascript.Context(). This is also recommended by the Java docs in org.mozilla.javascript.Context()