High CPU Utilization in java application - why?

前端 未结 6 715
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-29 22:44

I have a Java Application (web-based) that at times shows very high CPU Utilization (almost 90%) for several hours. Linux TOP command shows this. On application res

6条回答
  •  一生所求
    2021-01-29 22:58

    Your first approach should be to find all references to Thread.sleep and check that:

    1. Sleeping is the right thing to do - you should use some sort of wait mechanism if possible - perhaps careful use of a BlockingQueue would help.

    2. If sleeping is the right thing to do, are you sleeping for the right amount of time - this is often a very difficult question to answer.

    The most common mistake in multi-threaded design is to believe that all you need to do when waiting for something to happen is to check for it and sleep for a while in a tight loop. This is rarely an effective solution - you should always try to wait for the occurrence.

    The second most common issue is to loop without sleeping. This is even worse and is a little less easy to track down.

提交回复
热议问题