一、背景
最近在学jvm调优,在使用jstack命令时,出现报错。网上查了好多,都没有找到合适解决方法。
二、解决方法
1.测试代码
public class T15_FullGC_Problem01 {
private static class CardInfo {
BigDecimal price = new BigDecimal(0.0);
String name = "张三";
int age = 5;
Date birthdate = new Date();
public void m() {
}
}
private static ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(50,
new ThreadPoolExecutor.DiscardOldestPolicy());
public static void main(String[] args) throws Exception {
executor.setMaximumPoolSize(50);
for (;;){
modelFit();
Thread.sleep(100);
}
}
private static void modelFit(){
List<CardInfo> taskList = getAllCardInfo();
taskList.forEach(info -> {
// do something
executor.scheduleWithFixedDelay(() -> {
//do sth with info
info.m();
}, 2, 3, TimeUnit.SECONDS);
});
}
private static List<CardInfo> getAllCardInfo(){
List<CardInfo> taskList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
CardInfo ci = new CardInfo();
taskList.add(ci);
}
return taskList;
}
}
2.在linux下启动程序
java -Xms200M -Xmx200M -XX:+PrintGC T15_FullGC_Problem01
3.通过top命令查看占用cpu和内存比价搞的进程
4.通过top -Hp命令查看进程中的线程,找出线程占用资源比较多的线程
5.通过jstack命令,查看详细信息
6.在第5步是,报错了
分析之后发现,需要将线程中的线程号转换为十六进制才行,起始jstack可以直接查询进程的进程号信息。
jstack直接加进程号是可以直接使用的