Optimization for JudoScript: JudoUtil.registerToBSF is an expensive method to call.
It seems to me that a scripting engine only needs to register with the BSF engine once. I think that JudoScript registers with the engine every time a script is invoked. In order to avoid this situation, I added a static variable to track the bsfStatus. In the test case that I was executed, I was able to reduce calls to Class.forName() from 8,061 to 43 and the created objects from 649,620 to 162. This also saved 2.6% of execution time.
public static String bsfStatus = "UNKNOWN"; public static void registerToBSF() { if (bsfStatus.equals("UNKNOWN")) { try { Class[] params = new Class[] {String.class, String.class, Class.forName("[Ljava.lang.String;")}; Method m = Class.forName("com.ibm.bsf.BSFManager").getMethod("registerScriptingEngine", params); Object[] vals = new Object[] {"judoscript", "com.judoscript.BSFJudoEngine", new String[] {"judo", "jud"}}; m.invoke(null, vals); bsfStatus = "AVAILABLE"; } catch (Exception e) { bsfStatus = "UNAVAILABLE"; } // if BSF is not there, so be it. } }