Hi Jim, this example shows it pretty well:
https://gist.github.com/tobsch/6026942 as the script itself is very simple and does nothing special. It's only its invocation or doPrivileged to be precise. This is the profiler output: Any ideas? Best, Tobias Am 17.07.2013 um 18:23 schrieb Jim Laskey (Oracle) <[email protected]>: > Tobias, > > We'll look into removing the doPrivileged on first entry (security is checked > elsewhere), but we need to do a security assessment before proceeding. > > That said, I would recommend as a best practice to use a per-thread > JavaScript loop instead, to avoid such issues. I generally use a > java.util.concurrent.LinkedBlockingQueue to "feed" the loop from other > threads. > > Cheers, > > -- Jim > > > > > On 2013-07-17, at 12:37 PM, Tobias Schlottke <[email protected]> > wrote: > >> Hi there, >> >> I've built a small case where I evaluate a compiled script equipped with a >> custom bindings. >> The script is equipped with some variables and and compiled like this: >> >> engine.put("shopId", "test"); >> runner = (Bindings) >> engine.compile(ad.getCondition_script().getCode()).eval(); >> >> afterwards, I execute the "run" method on the object returned by eval() like >> this: >> >> return (MyCustomObject) engine.invokeMethod(runner, "run", attr); >> >> the run method does local compilations but does not change anything so >> basically the runner is immutable. >> I access it from various threads. >> >> When profiling the code I see a lot of time spent in >> java.security.AccessController.doPrivileged() which is invoked in >> setNashornGlobal() if the globals changed. >> I'm a bit unsure what changed globals really mean because in my case nothing >> (either context nor bindings) changed and I wonder if it is necessary. >> >> Best, >> >> Tobias >
