设为首页收藏本站

LUPA开源社区

 找回密码
 注册
文章 帖子 博客
LUPA开源社区 首页 业界资讯 技术文摘 查看内容

每个Java开发者都应该知道的5个JDK工具

2014-11-21 10:58| 发布者: joejoe0332| 查看: 2597| 评论: 0|原作者: javapapers|来自: CSDN

摘要: 目前,有许多工具可以绑定到Java JDK上面,其中java.exe和javac.exe是每位Java工程师的必 备武器,与此同时,还有许多其它Java JDK工具呈现在大家眼前。大多数Java程序员都没有使用过这些工具,但如果使用,它们会让 ...


3.jcmd

  jcmd主要用来把诊断命令请求发送到Java JVM中,当JVM进程中没有jcmd参数列表时,jcmd就会立即运行。这相当于jps工具,我开始启动jconsole,并且把它作为参数传递到jcmd,得到如下结果,这个也可以通过进程id(pid)实现。 

C:\Users\Cycle>jconsole

C:\Users\Cycle>jcmd JConsole help
3344:
The following commands are available:
JFR.stop
JFR.start
JFR.dump
JFR.check
VM.native_memory
VM.check_commercial_features
VM.unlock_commercial_features
ManagementAgent.stop
ManagementAgent.start_local
ManagementAgent.start
Thread.print
GC.class_stats
GC.class_histogram
GC.heap_dump
GC.run_finalization
GC.run
VM.uptime
VM.flags
VM.system_properties
VM.command_line
VM.version
help
C:\Users\Cycle>jcmd JConsole VM.uptime 
3344:289.977 s
  VM.uptime显示了Java应用程序具体运行时间。 


  在调试的时候,下面的参数可以用于并发锁的线程堆栈溢出。

jcmd <pid> Thread.print -l


4.jhat

  jhat的全称是Java heap analysis tool。它主要是用来解析和浏览堆文件,jhat有时更像是一个可视化工具。jhat解析堆存储( heap dump)并启动一个webserver,然后用户可以在浏览器下查看堆。jhat支持对象查询语言(oql)和一些预先设计查询。OQL帮助可能在 

http://localhost:7000/oql/ 
http://localhost:7000/oqlhelp/


  jmap工具来生成堆转储,我们应该使用-dump参数,下面jhat工具可以使用的参数列表: 

C:\Users\Cycle>jhat -help
Usage:  jhat [-stack ] [-refs ] [-port ] [-baseline ] [-debug ] [-version] [-h|-help] 

        -J          Pass  directly to the runtime system. For
                          example, -J-mx512m to use a maximum heap size of 512MB
        -stack false:     Turn off tracking object allocation call stack.
        -refs false:      Turn off tracking of references to objects
        -port :     Set the port for the HTTP server.  Defaults to 7000
        -exclude :  Specify a file that lists data members that should
                          be excluded from the reachableFrom query.
        -baseline : Specify a baseline object dump.  Objects in
                          both heap dumps with the same ID and same class will
                          be marked as not being "new".
        -debug :     Set debug level.
                            0:  No debug output
                            1:  Debug hprof file parsing
                            2:  Debug hprof file parsing, no server
        -version          Report version number
        -h|-help          Print this help and exit
                    The file to read

For a dump file that contains multiple heap dumps,
you may specify which dump in the file
by appending "#" to the file name, i.e. "foo.hprof#3".

All boolean options default to "true"


  我给jconsole应用程序创建了一个堆转储文件,并使用以下命令来运行进程id 3344:

jmap -dump:format=b,file=heap.bin 3344


  现在,堆转储文件准备就绪,运行下面命令并且会启动一个服务: 

jmap -dump:format=b,file=heap.bin 3344


  在控制台输出结果:

C:\Users\Cycle\Desktop>jhat heap.bin
Reading from heap.bin...
Dump file created Sun Nov 16 19:26:35 IST 2014
Snapshot read, resolving...
Resolving 641209 objects...
Chasing references, expect 128 dots..................
Eliminating duplicate references.....................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.


  在浏览器中输入:http://localhost:7000/后便会出来堆转储的详细情况:

  例如,还可以在http://localhost:7000/histo/查看堆内存柱状图。



酷毙

雷人

鲜花

鸡蛋

漂亮
  • 快毕业了,没工作经验,
    找份工作好难啊?
    赶紧去人才芯片公司磨练吧!!

最新评论

关于LUPA|人才芯片工程|人才招聘|LUPA认证|LUPA教育|LUPA开源社区 ( 浙B2-20090187 浙公网安备 33010602006705号   

返回顶部