com.tagtraum.perf.classloading
Class BackgroundClassLoader

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--com.tagtraum.perf.classloading.BackgroundClassLoader
All Implemented Interfaces:
java.lang.Runnable

public class BackgroundClassLoader
extends java.lang.Thread

Loads and initializes classes in a separate thread. You may want to disable class garbage collection with the VM command line parameter -Xnoclassgc in order for this to have an effect.

This class is especially useful, when classes shall be loaded over a slow network, but aren't packaged in a zip or jar file. However, consider doing just that (using zip or jar files), before you try to enhance performance by using this class.

You may also use this class to preload and preinitialize classes, if you need a lot of classes later on in the life of your application. When you actually have to instantiate a class, you don't need to load and initialize it anymore. This may make applications slightly more responsive.

You may obtain a list of classes you might want to preload by running your application with the -verbose:class VM command line parameter.

Version:
$Id: $
Author:
Hendrik Schreiber
See Also:
Class.forName(java.lang.String), Class.forName(java.lang.String, boolean, java.lang.ClassLoader)

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
BackgroundClassLoader(java.lang.String[] classnames)
          Loads and initializes classes in a separate thread.
BackgroundClassLoader(java.lang.String[] classnames, boolean initialize, java.lang.ClassLoader classLoader)
          Loads and optionally initializes classes in a thread.
 
Method Summary
 void run()
          Loads the classes.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BackgroundClassLoader

public BackgroundClassLoader(java.lang.String[] classnames)
Loads and initializes classes in a separate thread. By default the priority of the thread is Thread.MIN_PRIORITY. You need to call Thread.start(), to start loading.

Parameters:
classnames - array of fully qualified classnames

BackgroundClassLoader

public BackgroundClassLoader(java.lang.String[] classnames,
                             boolean initialize,
                             java.lang.ClassLoader classLoader)
Loads and optionally initializes classes in a thread. By default the priority of the thread is Thread.MIN_PRIORITY. You need to call Thread.start(), to start loading.

Parameters:
initialize - if true, the loaded class is initialized
classnames - array of fully qualified classnames
classLoader - the ClassLoader to use
Method Detail

run

public void run()
Loads the classes. Errors are reported to System.err.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread


Copyright © 2002 Hendrik Schreiber
http://www.tagtraum.com/performance/
This software can be distributed under LGPL