virtualMachineClass= Class.forName(virtualMachineClassName);final Met..._getmethod("attach">
当前位置:   article > 正文

java虚拟机性能监控_java虚拟机性能监控

getmethod("attach

//需要将jdk安装lib目录下面的tools.jar放到项目里面

final String virtualMachineClassName = "com.sun.tools.attach.VirtualMachine";

//获取虚拟机控制权限

Class> virtualMachineClass= Class.forName(virtualMachineClassName);

final Method attachMethod = virtualMachineClass.getMethod("attach", String.class);

//获取tomcat进程id

final RuntimeMXBean runtime =ManagementFactory.getRuntimeMXBean();

final String info = runtime.getName();

final int index = info.indexOf("@");

String pid="0000";

if (index != -1) {

pid = info.substring(0, index);

}

WindowsVirtualMachine jvmVirtualMachine=(WindowsVirtualMachine)attachMethod.invoke(virtualMachineClass, pid);

%>

服务器线程信息

$(document).ready(function(){

});

function fn_collectMemory(){

Runtime.getRuntime().gc();

%>

window.location.reload();

}

 
 

Runtime lRuntime = Runtime.getRuntime();

out.print("
*** 内存统计开始 ***
");

out.print("虚拟机空闲内存: "+lRuntime.freeMemory()+"(B)="+lRuntime.freeMemory()/1024/1024+"(MB)
");

out.print("虚拟机最大内存: "+lRuntime.maxMemory()+"(B)="+lRuntime.maxMemory()/1024/1024+"(MB)
");

out.print("虚拟机内存总量: "+lRuntime.totalMemory()+"(B)="+lRuntime.totalMemory()/1024/1024+"(MB)
");

out.print("已用内存:"+(lRuntime.totalMemory()-lRuntime.freeMemory())+"(B)="+(lRuntime.totalMemory()-lRuntime.freeMemory())/1024/1024+"(MB)
");

out.print("可用处理器: "+lRuntime.availableProcessors()+"
");

out.print("*** 内存统计结束 ***
");

%>

 
 

out.println("***************************虚拟机堆内存快照***************************");

InputStream in =(InputStream)jvmVirtualMachine.heapHisto(new Object[]{"-all"});

BufferedReader bufferReader= new BufferedReader(new InputStreamReader(in, "utf-8"));

String s = null;

while((s=bufferReader.readLine()) != null){

out.println(s);

}

bufferReader.close();

%>

 
 

out.println("***************************服务器线程统计***************************");

int count=1,tomcatThread=0;;

for(Map.Entry statcTrace:Thread.getAllStackTraces().entrySet()){

Thread thread =(Thread)statcTrace.getKey();

StackTraceElement[] stack =(StackTraceElement[])statcTrace.getValue();

if(thread.equals(Thread.currentThread())){

continue;

}

String threadName =thread.getName();

out.print("\n第"+( count++)+"条线程:"+threadName+"\n");

if(threadName.contains("catalina-exec-")){//catalina-exec-为server.xml中的配置属性(默认为 http-端口号-)

tomcatThread++;

}

for(StackTraceElement element:stack){

out.print("\t"+element+"\n");

}

}

out.print("\r\n http线程数量:"+tomcatThread+"条\n");

%>

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号