一次服务器CPU占用100%的问题排查

今天写了一段垃圾代码,然后上服务器上运行,cpu瞬间飙到了100%,现记录一下问题排除过程~

1. 问题代码

@Component
public class TestComponent {

    @Autowired
    private UserService userService;

    @PostConstruct
    public void init() {
        new Thread(()->{
            while (true) {
                if ( userService.getUser() !=null) {
                    // do something 
                }
            }
        }).start();
    }
}

2. top 

3. 查找问题

3.1  top -Hp  18571, 找出最耗cpu的线程,结果发现18584是就耗了99.9%

3.2 将十进制的线程号转成十六进制

  printf "0x%x\n" 18584

3.3  jstack查找问题代码

  jstack 18571| vim +/0x4898 -

 

 跑去看TestComponent.java 的第19行~~~~ 死到这里了。。。。。 

猜你喜欢

转载自www.cnblogs.com/z-qinfeng/p/11723045.html
今日推荐