You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-user@jakarta.apache.org by Daling Xu <da...@yahoo.com> on 2007/07/05 16:59:08 UTC

Issue when run multiple script files simultaneously

Hi,
   
  I am using BSF and Rhino in my java application to execute javascript files.
   
  Because the requirement of my project, I need to run multiple instance of one script file simutaneously.  To avoid the memory issue, I used only one BSFManager instance for my whole application, and every time when I need to start executing a script file, I start a separate thread and use the only bsfManager instance to evaluate the script file.
   
  Then I noticed that, when I only have one thread, every thing is perfect; But when I have more than one threads, the script generate inconsistant, weird output; It looks that the multi thread scripts code interfere with each other.
  
Any one here ran into similar issue? Any idea?
  
Thanks
   
  Linda  

       
---------------------------------
Get the free Yahoo! toolbar and rest assured with the added security of spyware protection. 

Re: Issue when run multiple script files simultaneously

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Linda,

Daling Xu wrote:
> Yes, I can do that.
>    
>   In fact, at my first round of experiment, I created one new BSFManager every time when I need to run a script. By doing this the script all run correctly. Essentially, this is similar to having a pool because they have the pros that each script is executed in its own Rhino instance, but the cons is that I loaded different Rhino instance for each script runtime, that could consume more memory. 
>   
Yes, the question would be whether this consumption can be felt at all,
or - in the other extreme - whether it would render the application  to
be unusable.

>   So my question is: What's the final reason of the script interfere with each other when they are run in different thread but using the same Rhino instance. 
>    
>   I looked at the 
>   org.apache.bsf.engines.javascript.JavaScriptEngine.java.  It looks that the reason maybe in the initialize method. Every JavaScriptEngine is initialized with a Scriptable object 'global', then when the eval() method is called, it's always called using
>   cx.evaluateString(global, scriptText,source, lineNo,null);
>    
>   But I am not sure what's stored in the 'global', and why finally two scripts interfere with each other. 
>   
Unfortunately, I do not know what architecture/limitation Rhino would
have and if it was possible to invoke it differently, such that one
Rhino instance executes scripts concurrently (e.g. not sure what 
"org.mozilla.javascript.Context" does/allows for) . Maybe one of the
Rhino/Javascript BSF engine creators could help (* @author   Adam Peller
<pe...@lotus.com>,  * @author   Sanjiva Weerawarana,  * @author  
Matthew J. Duftler,  * @author   Norris Boyd)?

Short of that one would have to study that particular aspect of
Rhino/Javascript, maybe there are even threads on the Mozilla newsgroups
about this topic?

>   Is it conceptually correct to use the same 'global' for evaluating different script files?  And besides the way of using separate BSFManager instance for each thread, is there any way I still share the same BSFManager and Rhino instance but use different 'global' value for each thread? 
Again, not sure at all what 'global' encompasses. One would need to dig
into the Rhino/Javascript interpreter.

> Because I am really concerned about the memory issue of instanciating multiple BSFManager and Rhino engine.
>   
Maybe, you should not be preoccupied too much ?

Having a pool of BSFManagers used to deploy scripts with the help of
Rhino engines, what would be the maximum amount of instances you have to
deal with? Do you have any profilings that you could gather and share
with us?

Regards,

---rony




---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org


Re: Issue when run multiple script files simultaneously

Posted by Daling Xu <da...@yahoo.com>.
Yes, I can do that.
   
  In fact, at my first round of experiment, I created one new BSFManager every time when I need to run a script. By doing this the script all run correctly. Essentially, this is similar to having a pool because they have the pros that each script is executed in its own Rhino instance, but the cons is that I loaded different Rhino instance for each script runtime, that could consume more memory. 
   
  So my question is: What's the final reason of the script interfere with each other when they are run in different thread but using the same Rhino instance. 
   
  I looked at the 
  org.apache.bsf.engines.javascript.JavaScriptEngine.java.  It looks that the reason maybe in the initialize method. Every JavaScriptEngine is initialized with a Scriptable object 'global', then when the eval() method is called, it's always called using
  cx.evaluateString(global, scriptText,source, lineNo,null);
   
  But I am not sure what's stored in the 'global', and why finally two scripts interfere with each other. 
   
  Is it conceptually correct to use the same 'global' for evaluating different script files?  And besides the way of using separate BSFManager instance for each thread, is there any way I still share the same BSFManager and Rhino instance but use different 'global' value for each thread? Because I am really concerned about the memory issue of instanciating multiple BSFManager and Rhino engine.
   
   
  Thanks
   
  Linda

"Rony G. Flatscher" <Ro...@wu-wien.ac.at> wrote:
  Hi Linda,
> I am using BSF and Rhino in my java application to execute javascript files.
> 
> Because the requirement of my project, I need to run multiple instance of one script file simutaneously. To avoid the memory issue, I used only one BSFManager instance for my whole application, and every time when I need to start executing a script file, I start a separate thread and use the only bsfManager instance to evaluate the script file.
> 
> Then I noticed that, when I only have one thread, every thing is perfect; But when I have more than one threads, the script generate inconsistant, weird output; It looks that the multi thread scripts code interfere with each other.
> 
> Any one here ran into similar issue? Any idea?
> 
How about creating a pool of BSFManager instances and (re-)using the
instances to deploy the scripts such, that each BSFManager instance
serves one script executing in the same thread?

---rony



---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org



       
---------------------------------
Fussy? Opinionated? Impossible to please? Perfect.  Join Yahoo!'s user panel and lay it on us.

Re: Issue when run multiple script files simultaneously

Posted by "Rony G. Flatscher" <Ro...@wu-wien.ac.at>.
Hi Linda,
>   I am using BSF and Rhino in my java application to execute javascript files.
>    
>   Because the requirement of my project, I need to run multiple instance of one script file simutaneously.  To avoid the memory issue, I used only one BSFManager instance for my whole application, and every time when I need to start executing a script file, I start a separate thread and use the only bsfManager instance to evaluate the script file.
>    
>   Then I noticed that, when I only have one thread, every thing is perfect; But when I have more than one threads, the script generate inconsistant, weird output; It looks that the multi thread scripts code interfere with each other.
>   
> Any one here ran into similar issue? Any idea?
>   
How about creating a pool of BSFManager instances and (re-)using the
instances to deploy the scripts such, that each BSFManager instance
serves one script executing in the same thread?

---rony



---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-user-help@jakarta.apache.org