Health Center is an IBM monitoring and diagnostics tool for Java and is a free low-cost diagnostic tool and API for monitoring applications running on the IBM Java virtual machine (JVM). See part 1th for details on the operations that this API can perform. In this article, you will use the deadlock detection application developed in part 1th and add a method to analyze the view to show where the application spends most of its CPU cycles. (see download for the complete source code for the sample.) )
System Requirements
The Health Center API bundle need to install Eclipse 3.4 or Eclipse 4.x at least.
Testing the Application
In the 1th part, the application that generated the deadlock condition has been tested. In this article, we'll use a revision of the application that contains some features that will put pressure on the CPU. See download for related source code. Listing 1 shows an example of a code fragment:
Listing 1. New code snippet for Generatedeadlock source code
Private class Runslowmethods extends Thread {public void run () {SlowClassAndMethod1 sCAM1 = new Slowcla
SsAndMethod1 ();
SLOWCLASSANDMETHOD2 sCAM2 = new SlowClassAndMethod2 ();
Scam1.start ();
Scam2.start ();
Private class SlowClassAndMethod1 extends Thread {public void run () {while (true) {
SlowMethod1 ();
try {thread.sleep (2000);
catch (Interruptedexception e) {e.printstacktrace ();
}} private void SlowMethod1 () {String largestring = new String ("A String to add");
for (int i = 0; i < 1000000 i++) {largestring.concat (largestring); }} Private class SlowClassAndMethod2 extends Thread {public void run () {WHI
Le (True) {slowMethod2 ();
try {thread.sleep (2000); catch (INterruptedexception e) {e.printstacktrace ();
}} private void SlowMethod2 () {HashMap map = new HashMap ();
String largestring = new String ("Another string to add");
for (int i = 0; i < 1000000 i++) {map.put (I, largestring);
Largestring.concat (largestring); }
}
Start the program by using the Health Center agent that is connected to the program. To start the application using Java 5 SR10 and later, Java 6 SR5 and later, and Java 7, use the following command (see Figure 1):
Java-xhealthcenter Generatedeadlock
Figure 1. Start the application
To use the Java 5 SR9 and its earlier version or Java 6 SR4 and its earlier versions and launch the application through a proxy, use:
Java-agentlib:healthcenter-xtrace:output=healthcenter.out Generatedeadlock
You can download the IBM Developer Toolkit.