How is jstack being used to find the bottlenect of a java program

Jstack is a built-in tool of JVM which is used to analyze the performance of java program.It prints the stack information of a process to the standard output of your system.Of cause you can redirect the output of the jstack to a file for later analysis.When you want to find the bottleneck of a java program,you can use jstack.For example: first,run you program named "myprogram" on the server and then figure out the process id (pid:2133) of your program(you can use "ps" command in linux shell). the last,start the jstack tool during the running of your program like this:

jstack 2133 > out.txt

then you can analyse the content of "out.txt" to find out the bottlenect of your program.To make the result more accurate,you need to take samples randomly of the program process stack,This is rather simple,right?

But how can the content of the output file of the jstack show you the bottleneck ? To understand this you need to know what do the jstack have done when it works.

When the jstack works,it reads the current stack information of the process,and that's it,that's all the jstack do.The stack information will show you which functions are the process invoking at the point you run jstack and which function is invoked by which.Find out the most frequently invoked functions(there may be serveral of them) in your program from the stack sample files you take. These "Most Frequently Invoked Functions" is right the bottleneck of your program. 

why is  the  "Most Frequently Invoked Functions" the bottleneck of the program? Now let's make an explaination. The jstack caputre the stack information at one point during the running of the program, if some funcions' call information frequently appears in the jstack output sample file,that's indicating that the functions execution may take a long relatively long time,which is the reason why their stack information being easily caputured by jstack. So we can come to a conclusion:the most frequently appeared functions in the jstack output information are the bottlenecks of the program.

Do you understand now ?


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值