
说明
1、ThreadDump用于诊断Java应用程序的问题,可用于查找存储器泄漏,发现死锁线程等。
2、该系统可获得线程、线程运行状态、标识、调用等信息,包括完整的类名、执行方法、源代码所在行数等。
特点
可用于各种操作系统;
可以在各种Java应用服务器下使用;
可以在不影响系统性能的情况下使用;
问题可以直接定位在应用程序的代码行上。
实例
publicclassJStack{
publicstaticvoidmain(String[]args)throwsException{
...
Stringpid=args[optionCount];
Stringparams[];
if(locks){
params=newString[]{"-l"};
}else{
params=newString[0];
}
runThreadDump(pid,params);
...
}
//Attachtopidandperformathreaddump
privatestaticvoidrunThreadDump(Stringpid,Stringargs[])
throwsException{
VirtualMachinevm=null;
try{
vm=VirtualMachine.attach(pid);
}catch(Exceptionx){
...
}
//CasttoHotSpotVirtualMachineasthisisimplementationspecific
//method.
InputStreamin=((HotSpotVirtualMachine)vm)
.remoteDataDump((Object[])args);
//readtoEOFandjustprintoutput
byteb[]=newbyte[256];
intn;
do{
n=in.read(b);
if(n>0){
Strings=newString(b,0,n,"UTF-8");
System.out.print(s);
}
}while(n>0);
in.close();
vm.detach();
}
以上就是java中Thread Dump的介绍,希望对大家有所帮助。更多Java学习指路:Java基础
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END



















































暂无评论内容