Identify high CPU consumed thread for Java app

Posted by Vincent Ma on Oracle Blogs See other posts from Oracle Blogs or by Vincent Ma
Published on Fri, 30 Nov 2012 15:46:41 +0000 Indexed on 2012/11/30 17:12 UTC
Read the original article Hit count: 252

Filed under:

Following java code to emulate busy and Idle thread and start it.

import java.util.concurrent.*;
import java.lang.*;

public class ThreadTest {
    public static void main(String[] args) {
        new Thread(new Idle(), "Idle").start();
        new Thread(new Busy(), "Busy").start();
    }
}

class Idle implements Runnable {

    @Override
    public void run() {
        try {
            TimeUnit.HOURS.sleep(1);
        } catch (InterruptedException e) {
        }
    }
}

class Busy implements Runnable {
    @Override
    public void run() {
        while(true) {
            "Test".matches("T.*");
        }
    }
}

Using Processor Explorer to get this busy java processor and get Thread id it cost lots of CPU

see the following screenshot:

Cover to 4044 to Hexadecimal is oxfcc.

Using VistulVM to dump thread and get that thread.

see the following screenshot

In Linux you can use  top -H to get Thread information.

That it!

Any question let me know. Thanks




© Oracle Blogs or respective owner

Related posts about /Java /Java EE