activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Justin Lebar (JIRA)" <>
Subject [jira] Created: (AMQ-1875) Transport threads spawned from daemon threads should themselves be daemon threads
Date Tue, 05 Aug 2008 04:31:52 GMT
Transport threads spawned from daemon threads should themselves be daemon threads

                 Key: AMQ-1875
             Project: ActiveMQ
          Issue Type: Bug
          Components: Transport
    Affects Versions: 5.1.0
         Environment: Windows XP, JDK 1.6.0r6
            Reporter: Justin Lebar

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

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();

                       while (true) {
                            // Do some stuff, expecting the JVM to kill us when we're done.

                       // Unreached

                   } catch (Exception e) {


           // 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) {

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message