dev@glassfish.java.net

Re: IMPORTANT - Daemon Threads

From: Tom Mueller <tom.mueller_at_oracle.com>
Date: Wed, 13 Oct 2010 11:03:05 -0500

  Here is a list of the non-daemon threads that are current left after
the command Byron lists below:

"RMI Reaper" prio=10 tid=0x0862d000 nid=0x6aa1 in Object.wait() [0x8773f000]
"DestroyJavaVM" prio=10 tid=0x082a7400 nid=0x6a75 waiting on condition
[0x00000000]
"GlassFish Kernel Main Thread" prio=10 tid=0x0862ec00 nid=0x6a9f in
Object.wait() [0x877e1000]
"fileinstall-/scratch/trm/test/glassfish3/glassfish/modules/autostart/"
prio=10 tid=0x87c06800 nid=0x6a95 in Object.wait() [0x87976000]
"telnetconsole.Listener" prio=10 tid=0x09537400 nid=0x6a93 runnable
[0x879c7000]
"Thread-10" prio=10 tid=0x88379000 nid=0x6a87 in Object.wait() [0x87edf000]
"Thread-8" prio=10 tid=0x88374400 nid=0x6a86 in Object.wait() [0x87f30000]
"Thread-7" prio=10 tid=0x88368800 nid=0x6a85 in Object.wait() [0x87f81000]
"Thread-5" prio=10 tid=0x88366c00 nid=0x6a84 in Object.wait() [0x87fd2000]
"Thread-3" prio=10 tid=0x8834d400 nid=0x6a83 in Object.wait() [0x88023000]
"Thread-1" prio=10 tid=0x88356000 nid=0x6a82 waiting on condition
[0x88074000]
"FelixDispatchQueue" prio=10 tid=0x88950400 nid=0x6a7d in Object.wait()
[0x88b9e000]
"VM Thread" prio=10 tid=0x082f1400 nid=0x6a76 runnable
"VM Periodic Task Thread" prio=10 tid=0x0837e800 nid=0x6a7c waiting on
condition

The somewhat anonymous "Thread-#" threads are Grizzly selector threads:

         at
com.sun.grizzly.http.SelectorThread.startListener(SelectorThread.java:1272)
         - locked <0x94f32250> (a java.lang.Object)
         at
com.sun.grizzly.http.SelectorThread.run(SelectorThread.java:1112)
         at
com.sun.grizzly.http.SelectorThread.startEndpoint(SelectorThread.java:1199)
         at
com.sun.enterprise.v3.services.impl.GrizzlyListener.startEndpoint(GrizzlyListener.java:133)
         at
com.sun.enterprise.v3.services.impl.GrizzlyProxy$2.run(GrizzlyProxy.java:327)

If you file a bug on these, please make it a blocker for issue 13951.
Thanks.

Tom

On 10/13/2010 1:01 AM, Byron Nevins wrote:
> Here is the message to take away if you don't read the rest of the email:
>
> /If you create a Thread in GlassFish -- *always *make it a daemon
> thread -- unless you have a very good reason not to. I.e. use the
> OPPOSITE of the default for Thread creation.
> /
> It's trivial to do:
>
> Thread.setDaemon(true)
>
> =============================================
>
> You all probably know this already but I'll repeat anyways: when the
> main() method in a java application (even GlassFish is but a java
> application!) returns -- the JVM exits.
>
> Unless there are non-daemon threads left running. In that case the
> JVM waits for the threads to die. Now if the thread is like this one:
>
> "Thread-22" prio=6 tid=0x070c9400 nid=0x1608 runnable [0x08daf000]
> java.lang.Thread.State: RUNNABLE
> .... boring stack trace removed
> at
> com.sun.messaging.jmq.admin.jmsspi.JMSAdminImpl$StreamGobbler.run(JMSAdminImpl.java:1507)
>
> it never dies and the JVM will be waiting forever -- i.e. the Server
> is now permanently hung.
>
> Daemon threads will identify themselves as daemon like this:
> "fileinstall-C:\glassfish3\glassfish\nodes\localhost\i1/autodeploy/bundles/"
> *daemon *prio=6 tid=0x06176400 nid=0x5a0 in ...
>
> We take care of this sort of problem now with a System.exit() after
> stopping services. This is not ideal though. Please be very careful
> when creating long-running threads!
> We ought to be able to exit the JVM cleanly without resporting to the
> sledge hammer of System.exit().
>
> Do you have a non-daemon thread running that ought to be a daemon
> thread? Here is how you can find out:
>
> (0) Start DAS
> (1) run this in a browser:
> http://localhost:4848/__asadmin/stop-domain?force=false
> (2) ZOMBIE!!! Run jstack on the Zombie process to see all the threads
> that are preventing an orderly shutdown.
>
> (The browser technique will go away within a week so try it right away
> if you think you may have a "bad" thread)
>
>
> --
> Byron Nevins - Oracle Corporation
> Home: 650-359-1290
> Cell: 650-784-4123
> Sierra: 209-295-2188
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net For
> additional commands, e-mail: dev-help_at_glassfish.dev.java.net