Why my Java applets took much longer to load when I upgrade to Java Runtime Environment version 7

I was looking after a couple of Java applets that are used in our private network for more than a decade. Changing business requirements mandated the upgrade of the Java Runtime Environment from version 1.5 to version 1.7. That change had caused my Java applets to load very slowly. On Java Runtime Environment version 1.7, my applets took at least 20 times longer to load.

How did this happen? Why did my Java applets took significantly longer to load when I upgraded my Java Runtime Environment to version 7? This post records how I had managed to solve the mystery and gotten my applets to run like they were on Java Runtime Environment 1.5.

Turning on Java console when my applets start loading

An important thing that I had taken right after I took up the job of taking care of the Java applet was to switch on the debugging mechanisms that come with the next generation Java Plug-in.

With that, when my browser loads the web pages that contain my applets, a console panel appeared to give me more insight about what the Java plugin was doing to run my applets.

Initial observation - Java Plug-in took a long time to apply socket permission

I began to observe the browser screen side-by-side the Java console panel. One thing that I noticed was that the Java Plug-in took a long time to display something that looked like the following:

security: Grant socket perm for http://www.techcoil.com/helloworld.jar : java.security.Permissions@e4de50 (
 ("java.net.SocketPermission" "www.techcoil.com" "connect,accept,resolve")
)

This observation hinted that the loading speed of my Java applets were affected by policies. With that, I replaced the java.policy file with one that I got from a fresh installation of the Java runtime environment. And true enough, with the new java.policy file, my applets loaded in a flash.

Large policy file affects the loading speed on some clients

However, with the new java.policy file, some of my applets does not work as before. Some of them were not able to open the file dialog; some not able to send data back to the server endpoint. That was not acceptable - I had to make my applets load fast on 1.7 while maintaining their original functions.

I went on to inspect the java.policy file that we had been using for a decade. There were more than 50 policy rule entries that applied all permissions on all my Java applets.

As an initial step, I looked at the following areas to trim the size of my policy file:

  1. URLs that my users will never ever access.
  2. Redundant policy rules that are applied to Java applets that does not need permissions to function.

After some trimming, I was able to cut 80KB off my java.policy and that had that had enabled my Java applets to function on Java Runtime Environment 1.7 as they were before on Java Runtime Environment 1.5.

About Clivant

Clivant a.k.a Chai Heng enjoys composing software and building systems to serve people. He owns techcoil.com and hopes that whatever he had written and built so far had benefited people. All views expressed belongs to him and are not representative of the company that he works/worked for.