dev@glassfish.java.net

Re: IMPORTANT - Daemon Threads

From: Nigel Deakin <nigel.deakin_at_oracle.com>
Date: Wed, 13 Oct 2010 15:58:10 +0100

Byron Nevins wrote, on 13/10/2010 07:01:
> 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.
>

That's a MQ resource adapter thread, used to capture standard output from a managed local broker. That can safely be
daemonised. I've logged this as Bugster CR 6991663 (JMSRA StreamGobbler threads should be daemon threads).

Nigel