'. '

Modular Java SE

From APIDesign

(Difference between revisions)
Jump to: navigation, search
Line 3: Line 3:
There can be many reasons for having [[module system|modular]] [[JDK]], but to simplify things, let's stick with one: we want to reach a point in future, when it will be enough to download just a limited set of [[JDK]] to execute an applet/application/server, etc.
There can be many reasons for having [[module system|modular]] [[JDK]], but to simplify things, let's stick with one: we want to reach a point in future, when it will be enough to download just a limited set of [[JDK]] to execute an applet/application/server, etc.
 +
==== False Expectations ====
 +
Sometimes people expect to get better performance just by modularizing their application. This is probably a false expectation, at least in the initial step.
 +
 +
By trivially splitting a [[JAR]] into ten smaller ones, one can only increase the amount of work done by the system. Instead of opening just one [[JAR]] and reading list of its entries, one needs to do this operation ten times, and this is obviously slower, especially when operating system caches are empty (e.g. after boot). Also the mutual communication between the newly separated pieces of the application will require some some overhead. Not much, but certainly something.
 +
 +
I have faced this when I split the monolithic '''openide.jar''' - a [[JAR]] with majority of [[NetBeans]] [[API]]s back in 2005 (see the [http://openide.netbeans.org/proposals/arch/modularize.html project page] for more details). When I divided the big [[JAR]] into fifteen smaller, the start time of [[NetBeans]] IDE increased by 5%. I was seeking for reasons of such slowdown for the whole release and managed to eliminate it somehow, but the proper fix was still waiting to be discovered.
 +
 +
These days the [[NetBeans]] IDE starts faster then it used to before its ''modularization'' - we improved the infrastructure and made it more ''module friendly''. We created various caches (for content of META-INF/MANIFEST.MF files of all modules, for META-INF/services, for classes loaded during start, for layout of files on disk, [[NetBeansLayers]], etc.) and these days ([[NetBeans]] IDE 6.5, or 6.7) we don't open the modularized [[JAR]]s at all. Thus we have the deployment benefits as claimed in [[NetBeans Runtime Container#Manifesto|manifesto of modular programming]], while during runtime the system behaves like a monolithic application.
 +
 +
Modularization really pays off (we can easily deprecate obsoleted modules and make the system smaller), but it may take a little while. If you are seeking immediate improvements in terms of ms spend while loading a Hello World! application, you'd better refactor your code and classes. Modularization is not going to help you. Modularization is for those who seek long term improvements in deployment, ability to deprecate and more rapidly evolve the framework.
== java.applet and java.beans ==
== java.applet and java.beans ==

Revision as of 14:54, 16 June 2009

I like puzzles that tease my mind (a bit). Last week I've been introduced to one. Modularize JDK (a described at Mark Reinhold's blog). This page will capture my thoughts on this topic.

There can be many reasons for having modular JDK, but to simplify things, let's stick with one: we want to reach a point in future, when it will be enough to download just a limited set of JDK to execute an applet/application/server, etc.

False Expectations

Sometimes people expect to get better performance just by modularizing their application. This is probably a false expectation, at least in the initial step.

By trivially splitting a JAR into ten smaller ones, one can only increase the amount of work done by the system. Instead of opening just one JAR and reading list of its entries, one needs to do this operation ten times, and this is obviously slower, especially when operating system caches are empty (e.g. after boot). Also the mutual communication between the newly separated pieces of the application will require some some overhead. Not much, but certainly something.

I have faced this when I split the monolithic openide.jar - a JAR with majority of NetBeans APIs back in 2005 (see the project page for more details). When I divided the big JAR into fifteen smaller, the start time of NetBeans IDE increased by 5%. I was seeking for reasons of such slowdown for the whole release and managed to eliminate it somehow, but the proper fix was still waiting to be discovered.

These days the NetBeans IDE starts faster then it used to before its modularization - we improved the infrastructure and made it more module friendly. We created various caches (for content of META-INF/MANIFEST.MF files of all modules, for META-INF/services, for classes loaded during start, for layout of files on disk, NetBeansLayers, etc.) and these days (NetBeans IDE 6.5, or 6.7) we don't open the modularized JARs at all. Thus we have the deployment benefits as claimed in manifesto of modular programming, while during runtime the system behaves like a monolithic application.

Modularization really pays off (we can easily deprecate obsoleted modules and make the system smaller), but it may take a little while. If you are seeking immediate improvements in terms of ms spend while loading a Hello World! application, you'd better refactor your code and classes. Modularization is not going to help you. Modularization is for those who seek long term improvements in deployment, ability to deprecate and more rapidly evolve the framework.

java.applet and java.beans

The biggest obstacle preventing creation of limited parts of JDK that really work is to define such limited pieces, make them independent and yet keep binary compatibility for the whole Java SE. Let's look at one such problem and seek a solution.

Obviously you may be interested in using JavaBeans specification and you may not want to know anything about applets. Also you may want to use applets and don't care about introspection and BeanInfos provided by JavaBeans. Is this possible?

Well, there is a problem. The java.beans.AppletInitializer interface. It resides in beans, yet its signature contains java.applet.Applet. This means that the java.beans package has compile time dependency on java.applet. Does that mean whoever uses JavaBeans module in future, needs to install applet module as well?

I hope no. Anybody knows how to do it?

<comments/>

Personal tools
buy