public class Initializer extends Object
An initializer for all classes loaded by any given class loader.
Initialization of classes at startup (or during bundle activation)
ensures a significantly improved worst case execution time especially
if the classes has configuration logic
to be
executed then.
Javolution activator initialize Realtime
classes when started.
When running outside OSGi the method
javolution.osgi.internal.OSGiServices.initializeRealtimeClasses()
can be used to that effect..
Class loading can be performed in a lazy manner and therefore some parts of the class loading process may be done on first use rather than at load time. Javolution bundle activator ensure that all its classes are initialized at start up. The following code illustrates how this can be done for any bundle.
public class MyActivator implements BundleActivator { public void start(BundleContext bc) throws Exception { Initializer initializer = new Initializer(MyActivator.class.getClassLoader()); initializer.loadClass(com.foo.internal.UnreferencedClass.class); // Load explicitly classes not directly or indirectly referenced. ... initializer.initializeLoadedClasses(); // Recursive loading/initialization. ... // Continue activation } }
This utility use reflection to find the classes loaded and may not be supported on all platforms.
Modifier and Type | Field and Description |
---|---|
static Configurable<Boolean> |
SHOW_INITIALIZED
Indicates if the class being initialized should be logged
(default
false ). |
Constructor and Description |
---|
Initializer(ClassLoader classLoader)
Creates an initializer for the specified class loader.
|
Modifier and Type | Method and Description |
---|---|
boolean |
initializeLoadedClasses()
Initializes all the loaded classes.
|
void |
loadClass(Class<?> cls)
Loads the specified class (does not perform any initialization).
|
Class<?>[] |
loadedClasses()
Returns the classes loaded by the class loader of this initializer or
null if not supported by the platform. |
public static final Configurable<Boolean> SHOW_INITIALIZED
false
).public Initializer(ClassLoader classLoader)
public Class<?>[] loadedClasses()
null
if not supported by the platform.public void loadClass(Class<?> cls)
public boolean initializeLoadedClasses()
true
if initialization has been performed successfully;
false
otherwise.Copyright © 2005-2013 Javolution. All Rights Reserved.