源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

如何利用JConsole观察分析Java程序的运行并进行排错调优

  • 时间:2021-11-26 23:43 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:如何利用JConsole观察分析Java程序的运行并进行排错调优
[b]一、JConsole是什么[/b] 从Java 5开始 引入了 JConsole。JConsole 是一个内置 Java 性能分析器,可以从命令行或在 GUI shell 中运行。您可以轻松地使用 JConsole(或者,它更高端的 “近亲” VisualVM )来监控 Java 应用程序性能和跟踪 Java 中的代码。 [b]二、如何启动JConsole[/b] 1.如果是从命令行启动,使 JDK 在 PATH 上,运行 jconsole 即可。 2.如果从 GUI shell 启动,找到 JDK 安装路径,打开 bin 文件夹,双击 jconsole 。 当分析工具弹出时(取决于正在运行的 Java 版本以及正在运行的 Java 程序数量),可能会出现一个对话框,要求输入一个进程的 URL 来连接,也可能列出许多不同的本地 Java 进程(有时包含 JConsole 进程本身)来连接。如图所示: [img]http://files.jb51.net/file_images/article/201512/201512282347011.png[/img] 想分析那个程序就双击那个进程。 [b]三、如何设置JAVA程序运行时可以被JConsolse连接分析[/b] 1.本地程序(相对于开启JConsole的计算机),无需设置任何参数就可以被本地开启的JConsole连接(Java SE 6开始无需设置,之前还是需要设置运行时参数 -Dcom.sun.management.jmxremote ) 2.无认证连接 (下面的设置表示:连接的端口为8999、无需认证就可以被连接)
-Dcom.sun.management.jmxremote.port=8999 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false
3.如果考虑到安全因素,需要认证,需要安全连接,也是可以搞定的。参考:[url=http://download.oracle.com/javase/6/docs/technotes/guides/management/agent.html#gdenv]http://download.oracle.com/javase/6/docs/technotes/guides/management/agent.html#gdenv[/url] [b]四、JConsole如何连接远程机器的JAVA程序(举例说明)[/b] 1、写一个简单的一直运行的JAVA程序,运行在某台机器上如(192.168.0.181)
[url=http://wiki.uuwatch.com:8081/pages/createpage.action?spaceKey=dev&title=HotSpot&linkCreation=true&fromPageId=22315511]HotSpot[/url] VM garbage collector 下generational GC 的各代的划分图:   [img]http://files.jb51.net/file_images/article/201512/201512282347025.gif[/img] 关于GC,可以参考:[url=http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html]http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html[/url] [url=http://www.1sucai.cn/article/77131.htm]http://www.1sucai.cn/article/77131.htm[/url] [b]参考资料:[/b] [list=1] [*][url=http://download.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html]Monitoring and Management Using JConsole[/url] :[url=http://download.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html]http://download.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html[/url][/*] [*][url=http://download.oracle.com/javase/6/docs/technotes/guides/management/agent.html]http://download.oracle.com/javase/6/docs/technotes/guides/management/agent.html[/url] [url=http://download.oracle.com/javase/6/docs/technotes/guides/management/agent.html]Monitoring and Management Using JMX Technology[/url] :[url=http://download.oracle.com/javase/6/docs/technotes/guides/management/agent.html]http://download.oracle.com/javase/6/docs/technotes/guides/management/agent.html[/url][/*] [*][url=http://visualvm.dev.java.net/eclipse-launcher.html]Eclipse launcher for VisualVM[/url] : [url=http://visualvm.dev.java.net/eclipse-launcher.html]http://visualvm.dev.java.net/eclipse-launcher.html[/url][/*] [*][url=http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html]Tuning Garbage Collection with the 5.0 Java[tm] Virtual Machine[/url] : [url=http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html]http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html[/url][/*] [/list]
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部