Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java Application Problems: Diagnostics


Published on

Have you got a problem in your running application? Learn how to use standard tools to get root cause.

Published in: Technology
  • The #1 Woodworking Resource With Over 16,000 Plans, Download 50 FREE Plans... ♥♥♥
    Are you sure you want to  Yes  No
    Your message goes here
  • If you're interested in realtime garbage collection monitoring you can also take a look at this free VisualVM plugin:
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

Java Application Problems: Diagnostics

  1. 1. Java Application Problems Diagnostics Vitalii Tymchyshyn Twitter: @tivv00 Email:
  2. 2. ContentsProblem typesProblem causesPrepare in advanceDiagnostics checklistStack tracesJava memory
  3. 3. Common Problem typesResource underutilizationSlowness in long runSudden haltsDisappearing applicationsProblems under load
  4. 4. Common Root CausesDeadlocks / Wrong lock orderingNarrow points / Wide locksLeaksHidden exceptionsUnhandled exceptionsInvalid OS/JVM configuration
  5. 5. Prepare: Logging hintsLog stdout/stderr – it has JVM outputLog application start/stop with error codeEnable GC loggingLog exception if you dont rethrow or process itLog FATAL in any place you call System.exitLog all thread stacks in multithreading guard code
  6. 6. Prepare: Setting up VM-verbose:gc – output GC to stderr-XX:+HeapDumpOnOutOfMemoryError-XX:+PrintClassHistogram – print class histogram along with thread stacks on Ctrl- / kill -3-XX:MaxNewSize – tame new generation for large heaps
  7. 7. Diagnostics checklistCheck your host: CPU/IO/Network usage, serious swappingCheck your VM: Heap/GC times, finalizer thread blockDeadlocks/Lock contentionExternal servicesLeaks / Peaks / Working set increase
  8. 8. Unix OS metricstop, vmstat, iostat Load average < Cores * 10 System time < 30% Context switches < Cores * 10000 Wait time means IO Swap Used < RAM/4 Swap IN/OUT < 1mb/1
  9. 9. Listing running java VMsjps -vvm For current user (as most of JVM tools) Shows PID Shows full command line including JVM options, system variables, full class name and program options Especially useful if program was started with a script
  10. 10. Getting stack tracesCtrl-Break (windows) / Ctrl- (Unix)Kill -3 <PID>jstackjconsoleIDEdebugger
  11. 11. What stack can tell youObvious deadlocksNarrow pointsSimplistic CPU profilingExternal resource overutilization/deadlock
  12. 12. JVM memory structureJava HeapThread StacksNative memory (UI can eat quite a lot)Permanent generation (classes / interned strings)Byte Buffers (often used as off-heap storage)Mapped files
  13. 13. Java HeapHas fixed upper limitStarts to take a lot of time when almost fullCan be tuned a lot (and often should be)GC activity logging should be enabledYou can enable printing overview on “kill -3”You can enable heap dump on OOM
  14. 14. Utilities to get heap informationjstack: some totalsjstat: detailed totalsjmap: get heap overview / dumpjconsole: force GC, collect GUI stats, make dump...Eclipse MAT: my preferred tool to analyze heap dumps