165 lines
No EOL
12 KiB
HTML
165 lines
No EOL
12 KiB
HTML
<!DOCTYPE html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="tool" content="leanote-desktop-app">
|
||
<title>java常用工具的作用及用法</title>
|
||
<style>
|
||
|
||
*{font-family:"lucida grande","lucida sans unicode",lucida,helvetica,"Hiragino Sans GB","Microsoft YaHei","WenQuanYi Micro Hei",sans-serif;}
|
||
|
||
body {
|
||
margin: 0;
|
||
}
|
||
|
||
/*公用文字样式*/
|
||
h1{font-size:30px}h2{font-size:24px}h3{font-size:18px}h4{font-size:14px}
|
||
.note-container{
|
||
width:850px;
|
||
margin:auto;
|
||
padding: 10px 20px;
|
||
box-shadow: 1px 1px 10px #eee;
|
||
}
|
||
#title {
|
||
margin: 0;
|
||
}
|
||
table {
|
||
margin-bottom: 16px;
|
||
border-collapse: collapse;
|
||
}
|
||
table th, table td {
|
||
padding: 6px 13px;
|
||
border: 1px solid #ddd;
|
||
}
|
||
table th {
|
||
font-weight: bold;
|
||
}
|
||
|
||
table tr {
|
||
background-color: none;
|
||
border-top: 1px solid #ccc;
|
||
}
|
||
table tr:nth-child(2n) {
|
||
background-color: rgb(247, 247, 249);
|
||
}
|
||
.mce-item-table, .mce-item-table td, .mce-item-table th, .mce-item-table caption {
|
||
border: 1px solid #ddd;
|
||
border-collapse: collapse;
|
||
padding: 6px 13px;
|
||
}
|
||
blockquote {
|
||
border-left-width:10px;
|
||
background-color:rgba(128,128,128,0.05);
|
||
border-top-right-radius:5px;
|
||
border-bottom-right-radius:5px;
|
||
padding:15px 20px;
|
||
border-left:5px solid rgba(128,128,128,0.075);
|
||
}
|
||
blockquote p {
|
||
margin-bottom:1.1em;
|
||
font-size:1em;
|
||
line-height:1.45
|
||
}
|
||
blockquote ul:last-child,blockquote ol:last-child {
|
||
margin-bottom:0
|
||
}
|
||
pre {
|
||
padding: 18px;
|
||
background-color: #f7f7f9;
|
||
border: 1px solid #e1e1e8;
|
||
border-radius: 3px;
|
||
display: block;
|
||
}
|
||
code {
|
||
padding: 2px 4px;
|
||
font-size: 90%;
|
||
color: #c7254e;
|
||
white-space: nowrap;
|
||
background-color: #f9f2f4;
|
||
border-radius: 4px;
|
||
}
|
||
.footnote {
|
||
vertical-align: top;
|
||
position: relative;
|
||
top: -0.5em;
|
||
font-size: .8em;
|
||
}
|
||
|
||
hr {
|
||
margin:2em 0
|
||
}
|
||
img {
|
||
max-width:100%
|
||
}
|
||
pre {
|
||
word-break:break-word
|
||
}
|
||
p,pre,pre.prettyprint,blockquote {
|
||
margin:0 0 1.1em
|
||
}
|
||
hr {
|
||
margin:2em 0
|
||
}
|
||
img {
|
||
max-width:100%
|
||
}
|
||
.sequence-diagram,.flow-chart {
|
||
text-align:center;
|
||
margin-bottom:1.1em
|
||
}
|
||
.sequence-diagram text,.flow-chart text {
|
||
font-size:15px !important;
|
||
font-family:"Source Sans Pro",sans-serif !important
|
||
}
|
||
.sequence-diagram [fill="#ffffff"],.flow-chart [fill="#ffffff"] {
|
||
fill:#f6f6f6
|
||
}
|
||
.sequence-diagram [stroke="#000000"],.flow-chart [stroke="#000000"] {
|
||
stroke:#3f3f3f
|
||
}
|
||
.sequence-diagram text[stroke="#000000"],.flow-chart text[stroke="#000000"] {
|
||
stroke:none
|
||
}
|
||
.sequence-diagram [fill="#000"],.flow-chart [fill="#000"],.sequence-diagram [fill="#000000"],.flow-chart [fill="#000000"],.sequence-diagram [fill="black"],.flow-chart [fill="black"] {
|
||
fill:#3f3f3f
|
||
}
|
||
ul,ol {
|
||
margin-bottom:1.1em
|
||
}
|
||
ul ul,ol ul,ul ol,ol ol {
|
||
margin-bottom:1.1em
|
||
}
|
||
kbd {
|
||
padding:.1em .6em;
|
||
border:1px solid rgba(63,63,63,0.25);
|
||
-webkit-box-shadow:0 1px 0 rgba(63,63,63,0.25);
|
||
box-shadow:0 1px 0 rgba(63,63,63,0.25);
|
||
font-size:.7em;
|
||
font-family:sans-serif;
|
||
background-color:#fff;
|
||
color:#333;
|
||
border-radius:3px;
|
||
display:inline-block;
|
||
margin:0 .1em;
|
||
white-space:nowrap
|
||
}
|
||
.toc ul {
|
||
list-style-type:none;
|
||
margin-bottom:15px
|
||
}
|
||
</style>
|
||
<!-- 该css供自定义样式 -->
|
||
<link href="../leanote-html.css" rel="stylesheet">
|
||
</head>
|
||
|
||
<body>
|
||
|
||
<div class="note-container">
|
||
<h1 class="title" id="leanote-title">java常用工具的作用及用法</h1>
|
||
<div class="content-html" id="leanote-content"><div><strong><span color="#ff0000" data-mce-style="color: #ff0000;" style="color: #ff0000;">jstatd</span></strong><br></div><div>启动jvm监控服务。它是一个基于rmi的应用,向远程机器提供本机jvm应用程序的信息。默认端口1099。<br></div><div>实例:jstatd -J-Djava.security.policy=my.policy<br><br>my.policy文件需要自己建立,内如如下:<br>grant codebase "file=$JAVA_HOME/lib/tools.jar" {<br>permission java.security.AllPermission;<br>};<br>这是安全策略文件,因为jdk对jvm做了jaas的安全检测,所以我们必须设置一些策略,使得jstatd被允许作网络操作<br></div><div><br></div><div><span color="#ff0000" data-mce-style="color: #ff0000;" style="color: #ff0000;"><strong>jps</strong></span><br>列出所有的jvm实例<br>实例:<br>jps<br>列出本机所有的jvm实例<br><br>jps 192.168.0.77<br>列出远程服务器192.168.0.77 机器所有的jvm实例,采用rmi协议,默认连接端口为1099<br>(前提是远程服务器提供jstatd服务)<br><br>输出内容如下:<br>jones@jones:~/data/ebook/java/j2se/jdk_gc$ jps<br>6286 Jps<br>6174 <wbr> <wbr>Jstat<br><br></div><p><strong><span color="#ff0000" face="Tahoma, Microsoft Yahei, simsun" data-mce-style="color: #ff0000; font-family: Tahoma, 'Microsoft Yahei', simsun;" style="color: #ff0000; font-family: Tahoma, 'Microsoft Yahei', simsun;">jconsole</span></strong></p><div><br>一个图形化界面,可以观察到java进程的 gc,class,内存等信息。虽然比较直观,但是个人还是比较倾向于使用jstat命令(在最后一部分会对jstat作详细的介绍)。<br><br></div><p><strong><span color="#ff0000" face="Tahoma, Microsoft Yahei, simsun" data-mce-style="color: #ff0000; font-family: Tahoma, 'Microsoft Yahei', simsun;" style="color: #ff0000; font-family: Tahoma, 'Microsoft Yahei', simsun;">jinfo</span></strong></p><div>(linux下特有)<br>观察运行中的java程序的运行环境参数:参数包括Java System属性和JVM命令行参数<br>实例:jinfo 2083<br>其中2083 就是java进程id号,可以用jps得到这个id号。<br>输出内容太多了,不在这里一一列举,大家可以自己尝试这个命令。<br><br></div><p><strong><span color="#ff0000" face="Tahoma, Microsoft Yahei, simsun" data-mce-style="color: #ff0000; font-family: Tahoma, 'Microsoft Yahei', simsun;" style="color: #ff0000; font-family: Tahoma, 'Microsoft Yahei', simsun;">jstack</span></strong></p><div>(linux下特有)<br>可以观察到jvm中当前所有线程的运行情况和线程当前状态<br>jstack 2083<br>jmap(linux下特有,也是很常用的一个命令)<br>观察运行中的jvm物理内存的占用情况。<br>参数如下:<br>-heap:打印jvm heap的情况<br>-histo:打印jvm heap的直方图。其输出信息包括类名,对象数量,对象占用大小。<br>-histo:live :同上,但是只答应存活对象的情况<br>-permstat:打印permanent generation heap情况<br><br>命令使用:<br>jmap -heap 2083<br>可以观察到New Generation(Eden Space,From Space,To Space),tenured generation,Perm Generation的内存使用情况<br><br>jmap -histo 2083 | jmap -histo:live 2083<br>可以观察 heap中所有对象的情况(heap中所有生存的对象的情况)。包括对象数量和所占空间大小。<br><br>写个脚本,可以很快把占用heap最大的对象找出来,对付内存泄漏特别有效。<br><br></div><p><strong><span color="#ff0000" face="Tahoma, Microsoft Yahei, simsun" data-mce-style="color: #ff0000; font-family: Tahoma, 'Microsoft Yahei', simsun;" style="color: #ff0000; font-family: Tahoma, 'Microsoft Yahei', simsun;">jstat</span></strong></p><div><br>最后要重点介绍下这个命令。<br>这是jdk命令中比较重要,也是相当实用的一个命令,可以观察到classloader,compiler,gc相关信息<br>具体参数如下:<br>-class:统计class loader行为信息<br>-compile:统计编译行为信息<br>-gc:统计jdk gc时heap信息<br>-gccapacity:统计不同的generations(不知道怎么翻译好,包括新生区,老年区,permanent区)相应的heap容量情况<br>-gccause:统计gc的情况,(同-gcutil)和引起gc的事件<br>-gcnew:统计gc时,新生代的情况<br>-gcnewcapacity:统计gc时,新生代heap容量<br>-gcold:统计gc时,老年区的情况<br>-gcoldcapacity: 统计gc时,老年区heap容量<br>-gcpermcapacity:统计gc时,permanent区heap容量<br>-gcutil:统计 gc时,heap情况<br>-printcompilation:不知道干什么的,一直没用过。<br><br>一般比较常用的几个参数是:<br>jstat -class 2083 1000 10 (每隔1秒监控一次,一共做10次)<br>输出内容含义如下:<br>Loaded <wbr> <wbr> <wbr> <wbr> Number of classes loaded.<br>Bytes <wbr> <wbr> <wbr> <wbr> Number of Kbytes loaded.<br>Unloaded <wbr> <wbr> <wbr> <wbr> Number of classes unloaded.<br>Bytes <wbr> <wbr> <wbr> <wbr> Number of Kbytes unloaded.<br>Time <wbr> <wbr> <wbr> <wbr> Time spent performing class load and unload operations.<br><br><br>jstat -gc 2083 2000 20(每隔2秒监控一次,共做10)<br>输出内容含义如下:<br>S0C <wbr> <wbr> <wbr> <wbr> Current survivor(存活的) space 0 capacity (KB).<br>EC <wbr> <wbr> <wbr> <wbr> Current eden space capacity (KB).<br>EU <wbr> <wbr> <wbr> <wbr> Eden space utilization (KB).<br>OC <wbr> <wbr> <wbr> <wbr> Current old space capacity (KB).<br>OU <wbr> <wbr> <wbr> <wbr> Old space utilization (KB).<br>PC <wbr> <wbr> <wbr> <wbr> Current permanent space capacity (KB).<br>PU <wbr> <wbr> <wbr> <wbr> Permanent space utilization (KB).<br>YGC <wbr> <wbr> <wbr> <wbr> Number of young generation GC Events.<br>YGCT <wbr> <wbr> <wbr> <wbr> Young generation garbage collection time.<br>FGC <wbr> <wbr> <wbr> <wbr> Number of full GC events.<br>FGCT <wbr> <wbr> <wbr> <wbr> Full garbage collection time.<br>GCT <wbr> <wbr> <wbr> <wbr> Total garbage collection time.<br><br><br>监控内存使用情况 参数 (查看内存溢出相对有用)<br><br>jstat -gccause 2083 5000 (每隔5秒监控一次)<br>输出内容含义如下:<br><br>S0 <wbr> <wbr> <wbr> <wbr> Survivor space 0 utilization as a percentage of the space's current capacity.<br>S1 <wbr> <wbr> <wbr> <wbr> Survivor space 1 utilization as a percentage of the space's current capacity.<br>E <wbr> <wbr> <wbr> <wbr> Eden space utilization as a percentage of the space's current capacity.<br>O <wbr> <wbr> <wbr> <wbr> Old space utilization as a percentage of the space's current capacity.<br>P <wbr> <wbr> <wbr> <wbr> Permanent space utilization as a percentage of the space's current capacity.<br>YGC <wbr> <wbr> <wbr> <wbr> Number of young generation GC events.<br>YGCT <wbr> <wbr> <wbr> <wbr> Young generation garbage collection time.<br>FGC <wbr> <wbr> <wbr> <wbr> Number of full GC events.<br>FGCT <wbr> <wbr> <wbr> <wbr> Full garbage collection time.<br>GCT <wbr> <wbr> <wbr> <wbr> Total garbage collection time.<br>LGCC <wbr> <wbr> <wbr> <wbr> Cause of last Garbage Collection.<br>GCC <wbr> <wbr> <wbr> <wbr> Cause of current Garbage Collection.<br></div><p><br></p></div>
|
||
</div>
|
||
|
||
<!-- 该js供其它处理 -->
|
||
<script src="../leanote-html.js"></script>
|
||
</body>
|
||
</html> |