First time performance penalty when JVM Loads
| Date: | July 2005 |
|---|---|
| Product/Release: | LANSA Integrator |
| Abstract: | Preventing JVM to unload classes from memory after 20 minutes |
| Submitted By: | LANSA Technical Support |
Description:
The "first time performance penalty" happens when the Java Virtual Machine loads the class into memory for the first time. If a class has not been used for 20 minutes the JVM unloads the class from memory. So when the service is used again at a later date, the class has to be reloaded (load penalty again).
To overcome the first time penalty, a custom Startup class has been written to create a thread that runs every 20 minutes to load the classes and keep them in memory.
Note: You do not need to just load the classes, you could execute a dummy XML transform or dummy SOAP transaction, etc.
You could also try the *NOCLASSGC option on the STRJSM command.
STRJSM OPTION(*NOCLASSGC)
noclassgc turns off garbage collection of Java classes. By default, the Java interpreter reclaims space for unused Java classes during garbage collection.
Note: If you are going to use the sample below, remember to remove the System.out.println lines. They are only there for debug and to illustrate the logic.
Sample Startup Class
package com.acme ;
public final class ActiveStartup implements Runnable
{
private int m_sleepTime = 0 ;
public ActiveStartup ()
{
/*
JSMManager uses the zero argument constructor
*/
int seconds = 60 * 20 ; // Every 20 minutes
Thread thread = new Thread ( new ActiveStartup ( seconds ) ) ;
thread.start () ;
}
public ActiveStartup ( int seconds )
{
/*
Specify sleep time
*/
if ( seconds <= 0 )
{
seconds = 0 ;
}
m_sleepTime = seconds * 1000 ;
}
public void run ()
{
if ( m_sleepTime == 0 )
{
/*
JSMManager call
*/
System.out.println ( "JSM warmup call" ) ;
try
{
warmup () ;
}
catch ( Exception e )
{
e.printStackTrace () ;
}
return ;
}
/*
ActiveStartup call with sleep time
*/
while ( true )
{
try
{
Thread.sleep ( m_sleepTime ) ;
System.out.println ( "ActiveStartup repeat warmup call" ) ;
warmup () ;
}
catch ( Exception e )
{
e.printStackTrace () ;
}
}
}
private final void warmup () throws Exception
{
System.out.println ( "ActiveStartup: warmup" ) ;
}
}