Add method analysis view to deadlock detection application via health Center API

Source: Internet
Author: User
Tags sleep thread

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.