Slashdot Mirror


Initializing all Java classes at Start-Up

Jean-Marie Dautelle writes "Java classes are initialized at first-use only which can introduce significant runtime delays detrimental to real-time or games applications (for which accurate scheduling is often required). To solve this problem, the latest open-source Javolution library supports initialization of all Java classes at start-up (e.g. javolution.lang.ClassInitializer.initializeAll(); // Initialize runtime classes (rt.jar) and all classes in classpath). Note: Runtime class initialization (rt.jar) takes typically a few seconds and about 3 Mbytes of memory."

6 of 56 comments (clear)

  1. tumbleweed? by Cronky · · Score: 4, Funny

    system.tumbleWeed.initialise() ?

  2. Re:Is this newsworthy? by Threni · · Score: 3, Funny

    >Making a function that calls System.XYZ.Init() for each xyz is newsworthy?
    >Egad... Time to submit my hello world-programs...

    My hello world program takes a array of char to describe which world is being greeted. The version under development will accept an array of pointers to strings so that more than one world can be greeted.

  3. Re: How long would it take to write this? by Carl+Rosenberger · · Score: 3, Informative

    How long would it take someone to write this themselves if they needed it? 10 minutes?

    Maybe a day ?

    (1) Identify all files and directories that can be found in the CLASSPATH.
    (2) Look at the directories and add all contained files to the list of files.
    (3) Differentiate beween types of files:
    (4) Add .class files to the list of class names
    (5) Look through all zip format files (.jar, .zip, .war ... ) and find all class names in there.
    (6) Call ClassLoader#loadClass with all classnames.

    (5) will take longest to write yourself, but there should certainly already be code out there tht gets that done

    (6) Which ClassLoader to use? Surely the ClassLoader needs to be supplyable as a parameter.

  4. Very, very rarely a good idea by /ASCII · · Score: 4, Interesting
    There are two reasons why lazy initialization is almost always the better solution:
    • Not all classes are used. Why pay a memory and performance penalty for having e.g. the Java2d API installed if your application never uses it?
    • Startup time will suffer. A 3 second startup penalty for only the bare minimum runtime, and probably much more for any non-trivial application is a huge deal.

    The advantage of doing eager initialization is predictability, and in the case where almost all classes get initialized sooner or later (which would be very rare considering the size of the Java API) a slight performance increase.

    Maybe some kinds of games would benefit from this, but almost all other applications would benefit from more lazy initialization, not less.
    --
    Try out fish, the friendly interactive shell.
  5. Shameless Plug or Valid Selfpromotion? by dorkygeek · · Score: 5, Interesting

    Let's see. Submitter of story: Jean-Marie Dautelle. Javolution project owner: Jean-Marie Dautelle.

    --
    Windows is like decaf - it tastes like the real thing, but it won't get you through the day.
  6. Re:Benefits for anything other than games? by breadbot · · Score: 4, Interesting

    Sun has been talking about shared VMs for a while now -- I can't remember if it's scheduled for version 6 or 7 -- the object space would be partitioned among the running Java "processes", but only one JVM would be necessary. It would improve startup times, memory consumption, etc. They could all share one instance of rt.jar, for example, assuming it was process-safe (it may not be now, but fixing it would be something Sun would have to do for the actual release). I don't see it listed in the Java 6 (Mustang) notes (for example here), so I would guess that it's slated for versin 7 (Dolphin).