<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#ffffff">
On 04/15/2010 09:09 PM, Carlo de Wolf wrote:
<blockquote cite="mid:4BC76466.1020105@redhat.com" type="cite">On
04/15/2010 07:22 PM, Jaikiran Pai wrote:
<br>
<blockquote type="cite">Jaikiran Pai wrote:
<br>
<blockquote type="cite">However, there are some non-daemon threads
still active even after a
<br>
server shutdown:
<br>
<br>
"pool-15-thread-1" prio=10 tid=0x8cb1ec00 nid=0x4d13 waiting on
<br>
condition [0x8e7a6000]
<br>
java.lang.Thread.State: TIMED_WAITING (parking)
<br>
at sun.misc.Unsafe.park(Native Method)
<br>
- parking to wait for<0xb20d6258> (a
<br>
java.util.concurrent.SynchronousQueue$TransferStack)
<br>
at
<br>
java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:198)
<br>
at
<br>
java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(SynchronousQueue.java:424)
<br>
at
<br>
java.util.concurrent.SynchronousQueue$TransferStack.transfer(SynchronousQueue.java:323)
<br>
at
java.util.concurrent.SynchronousQueue.poll(SynchronousQueue.java:874)
<br>
at
<br>
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:945)
<br>
at
<br>
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
<br>
at java.lang.Thread.run(Thread.java:619)
<br>
<br>
...
<br>
"pool-5-thread-1" prio=10 tid=0x8cfc2800 nid=0x4ce0 waiting on
condition
<br>
[0x8cdad000]
<br>
java.lang.Thread.State: WAITING (parking)
<br>
at sun.misc.Unsafe.park(Native Method)
<br>
- parking to wait for<0x97ece7e8> (a
<br>
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
<br>
at
java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
<br>
at
<br>
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:1925)
<br>
at
<br>
java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:358)
<br>
at
<br>
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:947)
<br>
at
<br>
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
<br>
at java.lang.Thread.run(Thread.java:619)
<br>
<br>
<br>
These pool-x-thread-y threads prevent the JVM from shutting down. The
<br>
thread names aren't very informative to figure out which service
started
<br>
those threads and why were those not shutdown. Anyone knows what these
<br>
threads are for and why they are hanging around after a server
shutdown?
<br>
<br>
</blockquote>
Thanks to Byteman (<a class="moz-txt-link-freetext" href="http://www.jboss.org/byteman">http://www.jboss.org/byteman</a>), I was able to figure
<br>
out what was creating these threads and why they were not cleaned up on
<br>
shutdown.
<br>
<br>
Out the two threads, one is from ShrinkWrap
<br>
(<a class="moz-txt-link-freetext" href="http://www.jboss.org/shrinkwrap">http://www.jboss.org/shrinkwrap</a>) which uses an ExecutorService to
<br>
create a cached thread pool. The thread created out of this pool was
<br>
staying around idle for 60 seconds (default) which was preventing (or
<br>
rather contributing to one minute delay in) the standalone client
shutdown.
<br>
<br>
However, the main culprit turns out to be NamingServer in AS which uses
<br>
an Exceutor backed by the default thread pool factory which creates
<br>
non-daemon threads
<br>
<a class="moz-txt-link-freetext" href="http://anonsvn.jboss.org/repos/jbossas/trunk/server/src/etc/deploy/naming-jboss-beans.xml:">http://anonsvn.jboss.org/repos/jbossas/trunk/server/src/etc/deploy/naming-jboss-beans.xml:</a>
<br>
<br>
<bean name="LookupPool">
<br>
<constructor factoryMethod="newFixedThreadPool"
<br>
factoryClass="java.util.concurrent.Executors">
<br>
<!-- At least 2 threads are required -->
<br>
<parameter>2</parameter>
<br>
</constructor>
<br>
</bean>
<br>
<br>
<bean name="RemoteNamingBean" class="org.jnp.server.Main">
<br>
...
<br>
<!-- The thread pool service used to control the bootstrap lookups
-->
<br>
<property name="lookupExector"><inject
bean="LookupPool"/></property>
<br>
</bean>
<br>
<br>
Locally, I have fixed this by passing a JBossThreadFactory (configured
<br>
to create daemon threads) to the Executor, so that it doesn't use the
<br>
default one. I have some questions around the configuration options for
<br>
JBossThreadFactory, for which I'll create a forum thread. I'll commit
<br>
the fix after that discussion.
<br>
<br>
By the way, as ALR pointed out on IRC, changing any random thread in AS
<br>
to mark them as daemon isn't always the right solution. But in case of
<br>
the NamingServer, IMO, changing it to daemon makes sense. If anyone has
<br>
objections, feel free to raise them.
<br>
<br>
-Jaikiran
<br>
<br>
</blockquote>
The clean way would be shutdownNow().
<br>
<strike>Now a runaway thread can still keep the server hanging.
</strike><br>
<br>
Carlo
<br>
</blockquote>
<br>
</body>
</html>