Friday Nov 30, 2012

Identify high CPU consumed thread for Java app

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




About

here is technology share in working and investigation

Search

Top Tags
Archives
November 2012 »
SunMonTueWedThuFriSat
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
       
Today