jakarta-bsf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daling Xu <daling...@yahoo.com>
Subject overhead of new BSFManager()
Date Tue, 23 Jan 2007 23:51:36 GMT
 
  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.
Mime
  • Unnamed multipart/alternative (inline, 8-Bit, 0 bytes)
View raw message