You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by "Timothy Bish (JIRA)" <ji...@apache.org> on 2011/07/08 23:32:16 UTC

[jira] [Closed] (AMQ-1875) Transport threads spawned from daemon threads should themselves be daemon threads

     [ https://issues.apache.org/jira/browse/AMQ-1875?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Timothy Bish closed AMQ-1875.
-----------------------------

    Resolution: Not A Problem

Improper configuration, solution given in issue comments.

> Transport threads spawned from daemon threads should themselves be daemon threads
> ---------------------------------------------------------------------------------
>
>                 Key: AMQ-1875
>                 URL: https://issues.apache.org/jira/browse/AMQ-1875
>             Project: ActiveMQ
>          Issue Type: Bug
>          Components: Transport
>    Affects Versions: 5.1.0
>         Environment: Windows XP, JDK 1.6.0r6
>            Reporter: Justin Lebar
>             Fix For: NEEDS_REVIEWED
>
>
> When a thread opens a connection over TCP, ActiveMQ spawns a transport thread.  The transport thread doesn't die until the connection is closed.  That's fine if the connection was opened by a non-daemon thread.  However, if the connection was opened by a daemon thread, the transport thread spawned is still set as a non-daemon thread.  If the daemon thread keeps its connection open, the process never dies, because a non-daemon is still alive.
> I think AMQ transport threads should inherit their daemon-ness from their parent thread, and they should be responsible for cleaning themselves up when the application quits, if necessary.
> Below is some code which exhibits the described behavior.  Run it and examine it with jstack or put a breakpoint right after the connection.start() to see that the transport thread is non-daemon.
> {code}
> import javax.jms.*;
> import org.apache.activemq.ActiveMQConnectionFactory;
> import org.apache.activemq.pool.PooledConnectionFactory;
> public class DaemonThreadTest {
>    public static void main(String[] args) throws Exception {
>        {
>            Thread t = new Thread(new Runnable() {
>                public void run() {
>                    try {
>                        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory( "", "", "tcp://localhost:61616"));
>                        Connection connection = connectionFactory.createConnection();
>                        connection.start();
>                        while (true) {
>                             // Do some stuff, expecting the JVM to kill us when we're done.
>                        }
>                        // Unreached
>                        connection.close();
>                    } catch (Exception e) {
>                        e.printStackTrace();
>                    }
>                }
>            });
>            t.setDaemon(true);
>            t.start();
>            // An infinite wait because I'm lazy.  You could replace this with a sleep, so long as you wait
>            // long enough for the daemon to initialize its connection.
>            Object lock = new Object();
>            synchronized(lock) {
>                lock.wait();
>            }
>        }
>    }
> }
> {code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira