Chapter 9. Java and WebSphere application design 291
program searches for it within the current class. If it is not found, the method is searched for
externally. Then, the external method is resolved and invoked, with the expected arguments
passed to the external method. Obviously, this process is more expensive than if the method
was located in the same class that called it.
One way to reduce this overhead is to specify methods as final, when possible, and then to
compile them with the javac -0 option. This causes
method inlining. This means that the
method call is replaced with the actual method instructions (bytecode) being copied into the
subclass that requests it. It eliminates the need for the application to resolve or search for the
method and to access the external method. This can result in substantial runtime
improvements if method resolution is a large portion of the application overhead.
9.1.6 Logging
Normally logging is an important part of the application. It’s frequently used during
development and quite valuable when troubleshooting an application. However, logging is
expensive in performance terms because it uses a lot of input/output (I/O) resources.
Instead of using System.out.println(...) directly in your program, you can use a class for
logging where you can switch on logging, depending on the severity of the information to log.
Example 9-4 provides a sample code.
Example 9-4 The EasyLog class
public class EasyLog {
public static int globalMinSeverity = 11;
public static final int DEVELOPMENT = 00;
public static final int INFO = 10;
public static final int WARNING = 40;
public static final int STOP = 80;
public static void writeLog(int severity, String thelog){
if (severity >= globalMinSeverity)
System.out.println(thelog);
}
public static void setGlobalSeverity(int severity){
globalMinSeverity = severity;
}
}
To use this class, initialize the severity level desired and then call to the writeLog method
instead of System.out.println:
EasyLog.setGlobalSeverity(EasyLog.INFO);
...
EasyLog.writeLog(EasyLog.INFO,"Test Running...”);
You can change the Global Severity at any moment during the runtime to switch on logging.
Note: This results in larger class sizes for the affected classes because a copy of the
methods bytecode is now embedded within the class. Since V4R4, creating a Java
program with OPTIMIZE(40) performs method resolution without requiring the java -0
option.

Get Maximum Performance with WebSphere Application Server V5.1 on iSeries now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.