<p>I have a problem with an application running on Fedora Core 6 with JDK 1.5.0_08.</p>
<p>After some amount of uptime (usually some days) threads begin getting stuck in native methods.</p>
<p>The threads are locked in something like this:</p>
<pre><code>&quot;pool-2-thread-2571&quot; prio=1 tid=0x08dd0b28 nid=0x319e waiting for monitor entry [0xb91fe000..0xb91ff7d4]
at java.lang.Class.getDeclaredConstructors0(Native Method)
</code></pre>
<p>or</p>
<pre><code>&quot;pool-2-thread-2547&quot; prio=1 tid=0x75641620 nid=0x1745 waiting for monitor entry [0xbc7fe000..0xbc7ff554]
at sun.misc.Unsafe.defineClass(Native Method)
</code></pre>
<p>Especially puzzling to me is this one:</p>
<pre><code>&quot;HealthMonitor-10&quot; daemon prio=1 tid=0x0868d1c0 nid=0x2b72 waiting for monitor entry [0xbe5ff000..0xbe5ff4d4]
at java.lang.Thread.dumpThreads(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1383)
</code></pre>
<p>The threads remain stuck until the VM is restarted.</p>
<p>Can anyone give me an idea as to what is happening here, what might be causing the native methods to block?
The monitor entry address range at the top of each stuck thread is different. How can I figure out what is holding this monitor?</p>

[{'answer_id': 38320, 'author': 'John Smithers', 'author_id': 1069, 'author_profile': 'https://Stackoverflow.com/users/1069', 'pm_score': 0, 'selected': False, 'text': '<p>Maybe you should use another jdk version.<br>\nFor your "puzzling one", there is a bug entry for 1.5.0_08. A memory leak is reported (I do not know, if this is related to your problem):<br>\n<a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6469701" rel="nofollow noreferrer">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6469701</a>  </p>\n\n<p>Also you could get the source code and look, what happens at line 1383. On the other side, it could just be the stack dump, after the original error occurred.</p>\n'}, {'answer_id': 152563, 'author': 'VoidPointer', 'author_id': 23424, 'author_profile': 'https://Stackoverflow.com/users/23424', 'pm_score': 3, 'selected': False, 'text': '<p>My initial suspicion would be that you are experiencing some sort of class-loader realted dead lock. I imagine, that class loading needs to be synchronized at some level because class information will become available for the entire VM, not just the thread where it was initially loaded.</p>\n\n<p>The fact that the methods on top of the stack are native methods seems to be pure coincidence, since part of the class loading mechanism happens to implemented that way.</p>\n\n<p>I would investigate further what is going on class-loading wise. Maybe some thread uses the class loader to load a class from a network location which is slow/unavailable and thus blocks for a really long time, not yielding the monitor to other threads that want to load a class. Investigating the output when starting the JVM with -verbose:class might be one thing to try.</p>\n'}, {'answer_id': 156378, 'author': 'David Smith', 'author_id': 17201, 'author_profile': 'https://Stackoverflow.com/users/17201', 'pm_score': 2, 'selected': False, 'text': '<p>I was having similar problems a few months ago and found the jthread(?) utility to be invaluable.  You give it the process ID for your Java application and it will dump the entire stack for each thread in your process.</p>\n\n<p>From the output of jthread, I could see one thread was trying to obtain a lock after having entered a monitor and another thread was trying to enter the monitor after obtaining the lock.  A recipe for deadlock.</p>\n\n<p>I was also wondering if your application was running into a garbage collection issue.  You say it runs for a couple days before it stops like this.  How long have you let it sit in the stuck state to see if maybe the GC ever finishes?</p>\n'}, {'answer_id': 177855, 'author': 'VoidPointer', 'author_id': 23424, 'author_profile': 'https://Stackoverflow.com/users/23424', 'pm_score': 1, 'selected': False, 'text': '<p>Can you find out which thread is actually synchronizing on the monitor on which the native method is waiting?\nAt least the thread-dump you get from the VM when you send it a SIGQUIT (kill -3) should show this information, as in</p>\n\n<pre><code>"Thread-0" prio=5 tid=0x0100b060 nid=0x84c000 waiting for monitor entry [0xb0c8a000..0xb0c8ad90]\n    at Deadlock$1.run(Deadlock.java:8)\n    - waiting to lock &lt;0x255e5b38&gt; (a java.lang.Object)\n...\n"main" prio=5 tid=0x01001350 nid=0xb0801000 waiting on condition [0xb07ff000..0xb0800148]\n    at java.lang.Thread.sleep(Native Method)\n    at Deadlock.main(Deadlock.java:21)\n- locked &lt;0x255e5b38&gt; (a java.lang.Object)\n</code></pre>\n\n<p>In the dumps you\'ve posted so far, I can\'t see any thread that is actually waiting to lock a specific monitor...</p>\n'}, {'answer_id': 5005799, 'author': 'Scott', 'author_id': 410755, 'author_profile': 'https://Stackoverflow.com/users/410755', 'pm_score': 0, 'selected': False, 'text': '<p>I found this thread after hitting the same problem - JDK 1.6.0_23 running on Linux with Tomcat 6.0.29.  Not sure those bits are relevant, though - what I did notice was that aside from many threads getting "stuck" in the getDeclaredConstructors() native method, the CPU was at 100% for the java process.  So, all request threads getting stuck here, CPU at 100%, thread dumps not showing any deadlocks (and no other threads doing any significant activity), it smelled like a thrashing garbage collector to me.  Sure enough, checked the server logs and there were numerous OutOfMemory errors - heap space was exhausted.</p>\n\n<p>Can\'t say that this is going to be the root cause of threads getting stuck here every time, but hopefully the info here will help others at least rule out this as a possible cause...</p>\n'}]
['https://Stackoverflow.com/questions/37551', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3904/']