jdk内置工具jstack查询有问题代码(具体到哪一行)
1,编写死循环代码类JstackCase;
2,编译该类
3,放到linux系统,并运行
4,新建连接到linux,使用top命令:查看当期那CPU使用情况
5.找到CPU使用率较高的线程ID:
命令:ps p 2511 -L -o pcpu,pid,tid,time,tname,cmd
6.查看进程16480中的信息:
命令:jstack -l 2511> 2511.pid
vi查看16480.pid文件:
代码:
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
public class JstackCase{
public static Executor executor = Executors.newFixedThreadPool(5);
public static Object lock = new Object();
public static void main(String[] args){
new Thread(new Task(),"asd").start();
}
static class Task implements Runnable{
@Override
public void run(){
synchronized(lock){
calculate();
}
}
public void calculate(){
int i = 0;
while(true){
System.out.println(i++);
}
}
}
}