为什么这个Java进程无法终止?

前端之家收集整理的这篇文章主要介绍了为什么这个Java进程无法终止?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在构建服务器上有一个间歇性问题,其中构建中的 Java进程无法终止,并且似乎继续运行(使用100%的cpu)永远(我已经看到它在周末运行了2天需要约10分钟). kill -9 pid似乎是停止进程的唯一方法.

我已经尝试在进程上调用kill -QUIT pid,但它似乎没有产生任何到STDOUT的堆栈跟踪(也许它没有响应信号?).没有-F强制选项的jstack似乎无法连接到正在运行的JVM,但是使用force选项会产生下面包含的输出.

不幸的是,即使有堆栈跟踪,我看不到任何明显的进一步调查路径.

据我所知,它显示了两个“BLOCKED”线程,它们运行了Object.wait(它们的堆栈似乎只包含核心Java代码,我们没有),第三个是“IN_VM”,没有堆栈输出.

我应该采取哪些步骤来收集有关问题原因的更多信息(或更好的是,我如何解决它)?

  1. $/opt/jdk1.6.0_29/bin/jstack -l -F 5546
  2. Attaching to process ID 5546,please wait...
  3. Debugger attached successfully.
  4. Server compiler detected.
  5. JVM version is 20.4-b02
  6. Deadlock Detection:
  7.  
  8. No deadlocks found.
  9.  
  10. Finding object size using Printezis bits and skipping over...
  11. Thread 5555: (state = BLOCKED)
  12.  
  13. Locked ownable synchronizers:
  14. - None
  15.  
  16. Thread 5554: (state = BLOCKED)
  17. - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
  18. - java.lang.ref.ReferenceQueue.remove(long) @bci=44,line=118 (Interpreted frame)
  19. - java.lang.ref.ReferenceQueue.remove() @bci=2,line=134 (Interpreted frame)
  20. - java.lang.ref.Finalizer$FinalizerThread.run() @bci=3,line=159 (Interpreted frame)
  21.  
  22. Locked ownable synchronizers:
  23. - None
  24.  
  25. Thread 5553: (state = BLOCKED)
  26. - java.lang.Object.wait(long) @bci=0 (Interpreted frame)
  27. - java.lang.Object.wait() @bci=2,line=485 (Interpreted frame)
  28. - java.lang.ref.Reference$ReferenceHandler.run() @bci=46,line=116 (Interpreted frame)
  29.  
  30. Locked ownable synchronizers:
  31. - None
  32.  
  33. Thread 5548: (state = IN_VM)
  34.  
  35. Locked ownable synchronizers:
  36. - None

(Java版本1.6.0更新29,在Scientific Linux版本6.0上运行)

更新:

运行strace -f -p 894生成一个看似无尽的流…

  1. [pid 900] sched_yield() = 0
  2. [pid 900] sched_yield() = 0
  3. ...

然后当Ctrl-Cd

  1. Process 894 detached
  2. ...
  3. Process 900 detached
  4. ...
  5. Process 909 detached

jmap -histo 894不连接但jmap -F -histo 894返回…

  1. Attaching to process ID 894,please wait...
  2. Debugger attached successfully.
  3. Server compiler detected.
  4. JVM version is 20.4-b02
  5. Iterating over heap. This may take a while...
  6. Finding object size using Printezis bits and skipping over...
  7. Finding object size using Printezis bits and skipping over...
  8. Object Histogram:
  9.  
  10. num #instances #bytes Class description
  11. --------------------------------------------------------------------------
  12. 1: 11356 1551744 * MethodKlass
  13. 2: 11356 1435944 * ConstMethodKlass
  14. 3: 914 973488 * ConstantPoolKlass
  15. 4: 6717 849032 char[]
  16. 5: 16987 820072 * SymbolKlass
  17. 6: 2305 686048 byte[]
  18. 7: 914 672792 * InstanceKlassKlass
  19. 8: 857 650312 * ConstantPoolCacheKlass
  20. 9: 5243 167776 java.lang.String
  21. 10: 1046 108784 java.lang.Class
  22. 11: 1400 87576 short[]
  23. 12: 1556 84040 * System ObjArray
  24. 13: 1037 64584 int[]
  25. 14: 103 60152 * ObjArrayKlassKlass
  26. 15: 622 54736 java.lang.reflect.Method
  27. 16: 1102 49760 java.lang.Object[]
  28. 17: 937 37480 java.util.TreeMap$Entry
  29. 18: 332 27960 java.util.HashMap$Entry[]
  30. 19: 579 27792 java.nio.HeapByteBuffer
  31. 20: 578 27744 java.nio.HeapCharBuffer
  32. 21: 1021 24504 java.lang.StringBuilder
  33. 22: 1158 24176 java.lang.Class[]
  34. 23: 721 23072 java.util.HashMap$Entry
  35. 24: 434 20832 java.util.TreeMap
  36. 25: 689 18936 java.lang.String[]
  37. 26: 238 17440 java.lang.reflect.Method[]
  38. 27: 29 16800 * MethodDataKlass
  39. 28: 204 14688 java.lang.reflect.Field
  40. 29: 330 13200 java.util.LinkedHashMap$Entry
  41. 30: 264 12672 java.util.HashMap
  42. ...
  43. 585: 1 16 java.util.LinkedHashSet
  44. 586: 1 16 sun.rmi.runtime.NewThreadAction$2
  45. 587: 1 16 java.util.Hashtable$EmptyIterator
  46. 588: 1 16 java.util.Collections$EmptySet
  47. Total : 79700 8894800
  48. Heap traversal took 1.288 seconds.

解决方法

这可能是由于内存不足造成的.我会尝试两件事情:

>通过添加JVM参数在OutOfMemory上启用自动堆转储

-XX:HeapDumpOnOutOfMemoryError XX:HeapDumpPath = / tmp>尝试使用JConsole连接到JVM,看看是否有异常模式

猜你在找的Java相关文章