Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java process is hanging for no apparent reason

Tags:

java

linux

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?

like image 323
Jad Y Avatar asked Dec 07 '10 12:12

Jad Y


4 Answers

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 jstack the process once it's hung to figure out what the threads are doing, and take it from there. It sounds like a deadlock or thrashing of some sort.

like image 91
NPE Avatar answered Sep 28 '22 10:09

NPE


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.

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().

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

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.

like image 37
Alex Miller Avatar answered Sep 28 '22 11:09

Alex Miller


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.

like image 26
AlexR Avatar answered Sep 28 '22 09:09

AlexR


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.

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!

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

like image 25
Jad Y. Avatar answered Sep 28 '22 10:09

Jad Y.