setNashornGlobal usage
Jim Laskey (Oracle)
james.laskey at oracle.com
Wed Jul 17 09:23:02 PDT 2013
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 <tobias.schlottke at gmail.com> 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
More information about the nashorn-dev
mailing list