且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java 阻塞问题:为什么 JVM 会阻塞许多不同类/方法中的线程?

更新时间:2022-06-10 23:08:01

这些大致按照我尝试它们的顺序列出,具体取决于收集的证据:

These are listed roughly in the order I would try them, depending on the evidence collected:

  • 您是否查看过 GC 行为?你有记忆压力吗?这可能会导致 newInstance() 和上面的其他一些被阻止.使用 -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -verbose:gc 运行您的 VM 并记录输出.您是否在故障/锁定时间附近看到过多的 GC 时间?
    • 条件是否可重复?如果是这样,请尝试在 JVM (-Xmx) 中使用不同的堆大小,并查看行为是否发生重大变化.如果是这样,请查找内存泄漏或为您的应用正确调整堆大小.
    • 如果前一个很难,并且您没有收到 OutOfMemoryError,您可以调整 GC 可调参数...参见 JDK6.0 XX 选项,或 JDK6.0 GC 调优白皮书.具体看-XX:+UseGCOverheadLimit-XX:+GCTimeLimit及相关选项.(注意这些没有很好的记录,但可能有用...)
    • Have you looked at GC behavior? Are you under memory pressure? That could result in newInstance() and a few others above being blocked. Run your VM with -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -verbose:gc and log the output. Are you seeing excessive GC times near the time of failure/lockup?
      • Is the condition repeatable? If so, try with varying heap sizes in the JVM (-Xmx) and see if the behavior changes substantially. If so, look for memory leaks or properly size the heap for your app.
      • If the previous is tough, and you're not getting an OutOfMemoryError when you should, you can tune the GC tunables... see JDK6.0 XX options, or JDK6.0 GC Tuning Whitepaper. Look specifically at -XX:+UseGCOverheadLimit and -XX:+GCTimeLimit and related options. (note these are not well documented, but may be useful...)