Hi Jim,

sounds pretty reasonable to me.
I still have the problem that I want to return something in run() though, so 
this renders a bit more complicated.
I understand that you have to check security once but I don't really understand 
why in my case because the object should not have changed.
Do you have an Idea why the ScriptObjects are not equal?

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
> 

Reply via email to