cool hit counter 1024 On this day, I deliberately wrote a dead end_Intefrankly

1024 On this day, I deliberately wrote a dead end

Author: Zhai Zhijun

There are many reasons for 100% cpu, and a dead loop in a program is one of them. However, not everyone at work has the opportunity to step into this hole. I was one of the ones who didn't step on it. Life seems a little incomplete.

So, I made a very important decision: to write a dead loop in the program. Let's see what happens.

Not in a production environment, of course. I built a lab environment to do the experiment. It's just that this experimental setting can be used for more than just this dead-loop experiment. The following is a diagram of the structure of this environment.

As usual, using Vagrant + Virtualbox + Ansible to automate the build environment.

We'll write a simple Spring MVC application, and then one of the interfaces will have dead-end code in it: the

Here's my own attempt to figure out this dead end loop.

I. Use top, to see which process is the problem

I ask once.

Then, I opened a new window and requested it once more

Here, I'm curious about the CPU not going to 200%. It's been between 120% and 130%. P.S. I must not have a solid knowledge of something, otherwise, I wouldn't have this doubt.

II. Heap space

Since there are no JVM heap space issues involved, executing jstat -gcutil 32593 1s didn't see anything wrong. 32593 is the java process ID and 1s means 1 second sampling.

III. Stacks

The heap is fine, just see which thread is high occupied.

List the threads of the java process, top -H -p

willjvm a warehousedump be over (of a period of time) jstack -l >> stack.log, Here I choose3596。

In the log, to find the corresponding thread, we need to find the corresponding thread from the stack log, but since the stack log uses hexadecimal, but the PID in top is again in decimal. So, it is necessary to manually convert the PID from decimal to hexadecimal. The hexadecimal turn of 3596 is 0xe0c

IV. Summary

From the course of this solution, we can already see a basic way to handle the CPU 100% situation! Hope this helps!

End-of-article promotion


Follow the public, all the Java you want is here!

1、XCode reads Excel data works with any database
2、 NET TransactionsImplicitTransactionTransactionScopeDisplayTransactionCommittableTransactionWebServiceTransactionOption
3、Machine learning 2018 school interview questions eBay startups
5、The thirdparty libraries that python hates to see

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送