opensubscriber
   Find in this group all groups
 
Unknown more information…

b : bsf-user@jakarta.apache.org 24 January 2007 • 7:51AM -0500

overhead of new BSFManager()
by Daling Xu

REPLY TO AUTHOR
 
REPLY TO GROUP





  In my project, I need to execute multiple (dosens, even hundreds) JavaScript files at the same time. And for each script file, I need to register a bean object for it. I need to use that bean in my script file, e.g.
myBeanName.method1(). But for each scipt, the bean object should be different. Also, I need to be able to stop specific script files at the run time.
  To satisfy all these requirements, I start a new BSFManager() for each script file:
  ...
Map threadMap = new Hashtable(); //
...
...
for( each scriptFileName ) {
Thread t = new Thread(){

  public void run() {
   BSFManager manager = new BSFManager();
     String lang = "JavaScript";
  
   //declare the specific bean object for the script file
   manager.declareBean("beanName", beanObjectForScriptI, MyBeanClass.class );
     manager.exec( lang,
       "Java", 0, 0,
       IOUtils.getStringFromReader(new FileReader(scriptFileName) ));
  }
   };

threadMap.put( scriptFileName, t ); //keep reference of thread of each script file engie
}
  Then, later when I call beanName.method1() in each script file, I am sure I called it on the correct beanObject instance. Also, I can stop the runnging script for scriptFileX by:
Thread t = (Thread) threadMap.get( scriptFileX );
t.stop();


But, I have some consern about the drawback which is the overhead of creating a BSFManager object for each script. By looking at the source code, I notice that each BSFManager maintain the loaded class of the script engine, e.g. JavaScriptEngine here.  Does that mean I am holding dosens even hundreds JavaScriptEngine class loaded in the memory by the former code scripet??
  Now my question is how big is this overhead? How much memory does it take? Can I avoid it?
  If I do it this way :
   BSFManager manager = new BSFManager();

for( each scriptFileName ) {
          
      String lang = "JavaScript";
      manager.declareBean("beanName", beanObjectForScriptI, MyBeanClass.class );    
      manager.exec( lang,
       "Java", 0, 0,
       IOUtils.getStringFromReader(new FileReader(scriptFileName) ));

}
  I am afraid that the declareBean method could overwrite the previously declared bean. Also, how can I stop the script execution for certain script files but keep others running at the runtime?


---------------------------------
Need Mail bonding?
Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.

Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.