Tuesday, September 07, 2004

Java Plugin Problems

On Internet Explorer, there is a known bug with JavaScript -> Applet -> Another Applet -> JavaScript calls. Now, also, on Mozilla there is a problem with JavaScript -> Applet -> JavaScript calls. If an applet is marked as scriptable, then the Java Runtime falls into an indefinite loop checking the security before allowing JavaScript to call the Applet. This loop can take up to a minute to terminate. This happens with J2SE version 5.0 release candidate.

This is beginning to make Java Applet integration with JavaScript on the page awkward!

3 comments:

William Billingsley said...

According to the engineer's response to the bug report, this is due to the way they've implemented JavaScript->Java calls (aggressive reflection). As such it's not a "bug", just quite slow for the first call.

Seems to me: This makes it quite important to have a small and fixed interface to the applet you're going to call. For instance, doing document.someApplet.getSomeOtherClass().doSomething() seems much slower than calling the method on the applet itself.

Anonymous said...

So what's the work-around - particularly with respect to Jollies?

William Billingsley said...

Wow - long time since I've updated this blog.

For the kind of tutorial applets I use, it seems to be enough to ensure that the method entry point in Java that you are calling is on the applet's own class and there aren't too many different API methods on that class (mine seem to have around a dozen) - as mentioned in the first comment. This seems to keep the amount the reflection mechanism analyses fairly small, and the delay won't be more than about 5 seconds. (I suspect the reflection mechanism must still be processing some classes other than the applet itself - 5 seconds is a long time to process 1 class - but it still keeps the number down).

This delay will only happen once per exercise - the first time you make a call, so personally I've found that to be ok. Particularly since the Javascript->Java calls happen when the user clicks particular links on the page - it seems to me that Web users are fairly used to occasional short delays from clicking hyperlinks.

From the original engineer's response, they were considering changing the mechanism in the 6.0 release, and the delay isn't there at all on IE.