Linux Java 进程无缘无故挂起

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4376543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 00:13:44  来源:igfitidea点击:

Java process is hanging for no apparent reason

javalinux

提问by Jad Y

I am running a Java process with Xmx2000m, the host OS is linux centos, jdk 1.6 update 22. Lately I have been experiencing a weird behavior in the process, it becomes totally unresponsive with no apparent reason, no logs, no errors, nothing.. I am using jconsole to monitor the processor, heap and Perm memory are not full, threads and loaded classes are not leaking.. Explanation anyone?

我正在运行一个带有 Xmx2000m 的 Java 进程,主机操作系统是 linux centos,jdk 1.6 update 22。最近我在进程中遇到了一个奇怪的行为,它变得完全没有响应,没有明显的原因,没有日志,没有错误,什么都没有。 . 我正在使用 jconsole 监视处理器,堆和 Perm 内存未满,线程和加载的类没有泄漏.. 解释一下?

回答by NPE

I doubt anyone can give you an explanation since there are lots of possible reasons and not nearly enough information. However, I suggest that you jstackthe process once it's hung to figure out what the threads are doing, and take it from there. It sounds like a deadlockor thrashingof some sort.

我怀疑任何人都可以给你一个解释,因为有很多可能的原因,而且没有足够的信息。但是,我建议您jstack在进程挂起后弄清楚线程在做什么,然后从那里开始处理。这听起来像是某种僵局颠簸

回答by AlexR

Agree with aix, but would like to add a couple of recommendataions. 1. check your system. Run top to see whether the system itself is healthy, CPU is not 100% and memory is available. If not, fix this. 2. application may freeze as a result of dead lock. Check this.

同意 aix,但想添加一些建议。1.检查你的系统。运行top查看系统本身是否健康,CPU不是100%,内存是否可用。如果没有,请修复此问题。2. 应用程序可能因死锁而冻结。检查这个。

回答by Jad Y

Threads can be traced using jvisualvm and jconsole, and deadlocks can be avoided too. Note that there are several network services each with separate thread pools, and they all become unreachable.

可以使用 jvisualvm 和 jconsole 跟踪线程,也可以避免死锁。请注意,有几个网络服务每个都有单独的线程池,并且它们都变得无法访问。

回答by Alex Miller

Do a thread dump. If you have access to the foreground process on Linux, use ctrl-\. Or use jstack to dump stack remotely. Or you can actually poke it through JMX via jconsole at MBeans/java.lang/Threading/Operations/dumpAllThreads.

做一个线程转储。如果您有权访问 Linux 上的前台进程,请使用ctrl-\. 或者使用 jstack 远程转储堆栈。或者您实际上可以通过 jconsole 通过 JMX 戳它MBeans/java.lang/Threading/Operations/dumpAllThreads

Without knowing more about your app, it's hard to speculate about the cause. Presumably your threads are either a) blocked or b) exited. If they are blocked, they could be waiting for I/O on a database or other operation OR they could be waiting on a lock or monitor (deadlocked). If a deadlock exists, the thread dump will tell you which threads are deadlocked, which lock, and (in Java 6) annotate the stack with where locks have been taken. You can also search for deadlocks with the JMX method, available through jconsole at MBeans/java.lang/Threading/Operations/find[Monitor]DeadlockedThreads().

如果不了解有关您的应用程序的更多信息,就很难推测原因。大概您的线程是 a) 阻塞或 b) 退出。如果它们被阻塞,它们可能正在等待数据库或其他操作上的 I/O,或者它们可能正在等待锁或监视器(死锁)。如果存在死锁,线程转储将告诉您哪些线程已死锁,哪些锁,并且(在 Java 6 中)用锁已被获取的位置注释堆栈。您还可以使用 JMX 方法搜索死锁,该方法可通过 jconsole 获得MBeans/java.lang/Threading/Operations/find[Monitor]DeadlockedThreads()

Or your threads may have received unhandled exceptions and exited. Check out Thread's uncaughtExceptionHandlers or (better) use Executors in java.util.concurrent.

或者您的线程可能已收到未处理的异常并退出。查看 Thread 的 uncaughtExceptionHandlers 或(更好)在 java.util.concurrent 中使用 Executors。

And finally, the other classic source of pauses in Java is GC. Run with -verbose:gc and other GC flags to see if it's doing a full GC collection. You can also turn this on dynamically in jconsole by flipping the flag at MBeans/java.lang/Memory/Attributes/Verbose.

最后,Java 中另一个经典的暂停来源是 GC。使用 -verbose:gc 和其他 GC 标志运行以查看它是否正在执行完整的 GC 收集。您还可以通过在 jconsole 中翻转标志来动态打开它MBeans/java.lang/Memory/Attributes/Verbose

回答by thotheolh

Could you elaborate more on what you are doing ? 2000for memory is rather a lot.

你能详细说明你在做什么吗?2000因为内存比较多。

回答by Jad Y

Check the jvisualvm of the process right before the crash. http://www.jadyounan.com/wp-content/uploads/2010/12/process.png

在崩溃之前检查进程的 jvisualvm。 http://www.jadyounan.com/wp-content/uploads/2010/12/process.png

回答by Jad Y.

Ok here are some updates I wanted to share:

好的,这里有一些我想分享的更新:

There is an incompatability between NTPL (Linux's new thread library) and the Java 1.6+ JVM. A random bug causes the JVM to hang and eat up 100% CPU.

NTPL(Linux 的新线程库)与 Java 1.6+ JVM 之间存在不兼容。一个随机错误导致 JVM 挂起并占用 100% 的 CPU。

To work around it set LD_ASSUME_KERNEL=2.4.1 before running the JVM, export LD_ASSUME_KERMEL=2.4.1 . This disables NTPL: problem solved!

要解决此问题,请在运行 JVM 之前设置 LD_ASSUME_KERNEL=2.4.1,导出 LD_ASSUME_KERMEL=2.4.1 。这将禁用 NTPL:问题解决了!

But for compatibility reasons, I'm still looking for a solution that uses NTPL.

但出于兼容性原因,我仍在寻找使用 NTPL 的解决方案。