Subj : Re: Sparodic NoClassDefFoundError: org/mozilla/javascript/optimizer/OptRuntime To : netscape.public.mozilla.jseng From : Igor Bukanov Date : Fri Jan 21 2005 08:52 pm redcoat wrote: > Nope, that still doesn't work!!!! > > Can you remember when this was last reported - we are pretty stuck. > Any other ideas where to look? I forgot that adding "synchronized" is not enough as it was necessary to add synchronized (parentLoader) as well. Here is the original report: -------------------------------------------------------------- ...... We've had some problems when using Rhino library with Tomcat. We ran multiple worker threads on the server side to execute a JavaScript, and occasionally but persistently Rhino would throw exceptions like java.lang.NoClassDefFoundError: org/mozilla/javascript/optimizer/OptRuntime at org.mozilla.javascript.gen.c3._c0(import) at org.mozilla.javascript.gen.c3.call(import) at org.mozilla.javascript.gen.c3.exec(import) We eventually found that the cause is that Rhino's classloader DefiningClassLoader doesn't synchronize the access to its parent loader, Tomcat's WebappClassLoader. Once the synchronization is done, no exceptions are thrown out. Now we have two choices 1. Fix Rhino's class loader DefiningClassLoader to synchronize the access to the parent loader, or 2. Fix Tomcat's class loader WebappClassLoader. Do you think that DefiningClassLoader should synchronize the access to its parent class loader? -------------------------------------------------------------- The fix was described later was: -------------------------------------------------------------- Here is what we did to DefiningClass.java - we made all methods "synchronized" and also synchronized the access to the parent loader in method loadClass, public synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException { Class cl = findLoadedClass(name); if (cl == null) { if (parentLoader != null) { synchronized(parentLoader) { cl = parentLoader.loadClass(name); } } else { cl = findSystemClass(name); } } if (resolve) { resolveClass(cl); } return cl; } -------------------------------------------------------------- Regards, Igor .