六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 23|回复: 0

Quick Troubleshooting Tips on Windows for Java SE 7

[复制链接]

升级  0.67%

11

主题

11

主题

11

主题

秀才

Rank: 2

积分
51
 楼主| 发表于 2013-2-3 10:45:41 | 显示全部楼层 |阅读模式
 
Quick Troubleshooting Tips on Windows for Java SE 7

This "Quick Start Guide" gives you some quick tips fortroubleshooting. The subsections list some typical functions thatcan help you in troubleshooting, including one or more ways to getthe information or perform the action.
These tips are organized as follows:
Hung, Deadlocked, or LoopingProcess
Post-mortem Diagnostics, Memory Leaks
Monitoring
Other Functions
Hung, Deadlocked, or LoopingProcess


  • Print thread stack for all Java threads:

    • Control-Break
    • jstack pid

  • Detect deadlocks:

    • Request deadlock detection: JConsole tool, Threads tab
    • Print information on deadlocked threads: Control-Break
    • Print lock information for a process: jstack -lpid

  • Get a heap histogram for a process:

    • Start Java process with -XX:+PrintClassHistogram, thenControl-Break
    • jmap -histo pid

  • Dump Java heap for a process in binary format to file:

    • jmap -dump:format=b,file=filename pid

  • Print shared object mappings for a process:

    • jmap pid

  • Print heap summary for a process:

    • Control-Break
    • jmap -heap pid

  • Print finalization information for a process:

    • jmap -finalizerinfo pid

  • Attach the command-line debugger to a process:

    • jdb -connectsun.jvm.hotspot.jdi.SAPIDAttachingConnector:pid=pid

Post-mortem Diagnostics, MemoryLeaks


  • Examine the fatal error log file. Default file name ishs_err_pidpid.log in the workingdirectory.
  • Create a heap dump:

    • Start the application with HPROF enabled: java-agentlib:hprof=file=file,format=bapplication; then Control-Break
    • Start the application with HPROF enabled: java-agentlib:hprof=heap=dump application
    • JConsole tool, MBeans tab
    • Start VM with -XX:+HeapDumpOnOutOfMemoryError; ifOutOfMemoryError is thrown, VM generates a heap dump.

  • Browse Java heap dump:

    • jhat heap-dump-file

  • Get a heap histogram for a process:

    • Start Java process with -XX:+PrintClassHistogram, thenControl-Break
    • jmap -histo pid

Monitoring

(jstat is not available on Windows 98 or WindowsME.)
Note: The vmID argument for the jstat command isthe virtual machine identifier. See the jstat man page for a detailed explanation.

  • Print statistics on the class loader:

    • jstat -class vmID

  • Print statistics on the compiler:

    • Compiler behavior: jstat -compiler vmID
    • Compilation method statistics: jstat -printcompilationvmID

  • Print statistics on garbage collection:

    • Summary of statistics: jstat -gcutil vmID
    • Summary of statistics, with causes: jstat -gccausevmID
    • Behavior of the gc heap: jstat -gc vmID
    • Capacities of all the generations: jstat -gccapacityvmID
    • Behavior of the new generation: jstat -gcnewvmID
    • Capacity of the new generation: jstat -gcnewcapacityvmID
    • Behavior of the old and permanent generations: jstat-gcold vmID
    • Capacity of the old generation: jstat -gcoldcapacityvmID
    • Capacity of the permanent generation: jstat-gcpermcapacity vmID

  • Monitor objects awaiting finalization:

    • JConsole tool, VM Summary tab
    • jmap -finalizerinfo pid
    • getObjectPendingFinalizationCount method injava.lang.management.MemoryMXBean class

  • Monitor memory:

    • Heap allocation profiles via HPROF: java-agentlib:hprof=heap=sites
    • JConsole tool, Memory tab
    • Control-Break prints generation information.
    Monitor CPU usage:

    • By thread stack: java -agentlib:hprof=cpu=samplesapplication
    • By method: java -agentlib:hprof=cpu=timesapplication
    • JConsole tool, Overview and VM Summary tabs

  • Monitor thread activity:

    • JConsole tool, Threads tab

  • Monitor class activity:

    • JConsole tool, Classes tab

Actions on a Remote DebugServer

First, attach the debug daemon jsadebugd, then executethe command:

  • Dump Java heap in binary format to a file: jmap-dump:format=b,file=filename hostID
  • Print shared object mappings: jmap hostID
  • Print heap summary : jmap -heap hostID
  • Print finalization information : jmap -finalizerinfohostID
  • Print lock information : jstack -l hostID
  • Print thread trace : jstack hostID
  • Print Java configuration information: jinfohostID
Other Functions


  • Interface with the instrumented Java virtual machines:

    • Monitor for the creation and termination of instrumented VMs(not Windows 98 or Windows ME): jstatd daemon
    • List the instrumented VMs (not Windows 98 or Windows ME):jps
    • Provide interface between remote monitoring tools and local VMs(not Windows 98 or Windows ME): jstatd daemon
    • Request garbage collection: JConsole tool, Memory tab

  • Print Java configuration information from a running process:

    • jinfo pid

  • Dynamically set, unset, or change the value of certain Java VMflags for a process:

    • jinfo -flag flag pid

  • Print command-line flags passed to the VM:

    • jinfo -flags

  • Print Java system properties:

    • jinfo -sysprops

  • Pass a Java VM flag to the virtual machine:

    • jconsole -Jflag ...
    • jhat -Jflag ...
    • jmap -Jflag ...

  • Print statistics of permanent generation of Java heap, by classloader:

    • jmap -permstat

  • Report on monitor contention:

    • java -agentlib:hprof=monitor=y application

  • Evaluate or execute a script in interactive or batch mode:

    • jrunscript

  • Interface dynamically with an MBean, via JConsole tool, MBeantab:

    • Show tree structure.
    • Set an attribute value.
    • Invoke an operation.
    • Subscribe to notification.

  • Run interactive command-line debugger:

    • Launch a new VM for the class: jdb class
    • Attach debugger to a running VM: jdb -attachaddress

 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表