1
votes

I am not able to start the JMS Connection, where the connection is created with ActiveMQConnectionFactory. Below is my code :

public static void main(String[] args) throws Exception {

    BrokerService broker = new BrokerService();
    try {
        broker.setUseJmx(true);
        broker.addConnector("vm://localhost:61616");
        broker.start();
        System.out.println("Broker started from EventManager  >>>");
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        ProducerConsumer pc = ProducerConsumer.getInstance();
        pc.sendMessage("TESTQ", "Hello");
    } catch (Exception e) {
        e.printStackTrace();
    }

ProducerConsumer Java Class :

   public static ProducerConsumer getInstance() throws Exception {
    if(produceConsume == null) {
        System.out.println(" synchronized Instanace created ");
        produceConsume = new ProducerConsumer();
    }
    return produceConsume;


private ProducerConsumer() throws Exception 
    {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(this.url);
        try {
            this.connection = connectionFactory.createConnection();
            this.connection.start();
        } catch (JMSException jms) {
            throw new Exception("Exception when active MQ establishes connections....", jms);
        }
    }

The code get stuck at start(), with the thread dump I can see the below stack

Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.0-b28 mixed mode):

"ActiveMQ Task-1" daemon prio=10 tid=0x00007fbe3c414800 nid=0x3543 in Object.wait() [0x00007fbe2a715000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000007d7443228> (a java.lang.Object) at org.apache.activemq.transport.failover.FailoverTransport.doReconnect(FailoverTransport.java:954) - locked <0x00000007d7443228> (a java.lang.Object) at org.apache.activemq.transport.failover.FailoverTransport$2.iterate(FailoverTransport.java:136) - locked <0x00000007d7443218> (a java.lang.Object) at org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:127) at org.apache.activemq.thread.PooledTaskRunner$1.run(PooledTaskRunner.java:48) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)

"ActiveMQConnection[ID:ayush-0791-50867-1412762440207-2:1] Scheduler" daemon prio=10 tid=0x00007fbe3c413000 nid=0x3542 in Object.wait() [0x00007fbe2a816000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000007d75d73a8> (a java.util.TaskQueue) at java.lang.Object.wait(Object.java:503) at java.util.TimerThread.mainLoop(Timer.java:526) - locked <0x00000007d75d73a8> (a java.util.TaskQueue) at java.util.TimerThread.run(Timer.java:505)

"ActiveMQ Broker[localhost] Scheduler" daemon prio=10 tid=0x00007fbe3c3e0000 nid=0x3541 in Object.wait() [0x00007fbe2a917000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000007d93fa080> (a java.util.TaskQueue) at java.util.TimerThread.mainLoop(Timer.java:552) - locked <0x00000007d93fa080> (a java.util.TaskQueue) at java.util.TimerThread.run(Timer.java:505)

"ActiveMQ Data File Writer" daemon prio=10 tid=0x00007fbe3c3d1800 nid=0x3540 in Object.wait() [0x00007fbe2aa18000]
java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000007d93fa3b8> (a org.apache.kahadb.journal.DataFileAppender$1) at java.lang.Object.wait(Object.java:503) at org.apache.kahadb.journal.DataFileAppender.processQueue(DataFileAppender.java:312) - locked <0x00000007d93fa3b8> (a org.apache.kahadb.journal.DataFileAppender$1) at org.apache.kahadb.journal.DataFileAppender$2.run(DataFileAppender.java:203)

"ActiveMQ Journal Checkpoint Worker" daemon prio=10 tid=0x00007fbe3c3cb000 nid=0x353f waiting on condition [0x00007fbe2ab19000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at org.apache.activemq.store.kahadb.MessageDatabase$3.run(MessageDatabase.java:296)

"KahaDB Scheduler" daemon prio=10 tid=0x00007fbe3c3c1000 nid=0x353e in Object.wait() [0x00007fbe2b32b000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000007d981f418> (a java.util.TaskQueue) at java.util.TimerThread.mainLoop(Timer.java:552) - locked <0x00000007d981f418> (a java.util.TaskQueue) at java.util.TimerThread.run(Timer.java:505)

"RMI RenewClean-[192.168.57.33:47976]" daemon prio=10 tid=0x00007fbde0005800 nid=0x353c in Object.wait() [0x00007fbe2ad1b000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000007d9889870> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135) - locked <0x00000007d9889870> (a java.lang.ref.ReferenceQueue$Lock) at sun.rmi.transport.DGCClient$EndpointEntry$RenewCleanThread.run(DGCClient.java:535) at java.lang.Thread.run(Thread.java:722)

"RMI Scheduler(0)" daemon prio=10 tid=0x00007fbdf0024800 nid=0x353b waiting on condition [0x00007fbe2ae1c000] java.lang.Thread.State: TIMED_WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x00000007850ffb10> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226) at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2082) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1090) at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:807) at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) at java.lang.Thread.run(Thread.java:722)

"GC Daemon" daemon prio=10 tid=0x00007fbdf0006800 nid=0x3539 in Object.wait() [0x00007fbe2b028000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000007850069b0> (a sun.misc.GC$LatencyLock) at sun.misc.GC$Daemon.run(GC.java:117) - locked <0x00000007850069b0> (a sun.misc.GC$LatencyLock)

"RMI Reaper" prio=10 tid=0x00007fbdf0004800 nid=0x3538 in Object.wait() [0x00007fbe2b129000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x0000000785000b98> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135) - locked <0x0000000785000b98> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151) at sun.rmi.transport.ObjectTable$Reaper.run(ObjectTable.java:351) at java.lang.Thread.run(Thread.java:722)

"RMI TCP Accept-0" daemon prio=10 tid=0x00007fbdf0003000 nid=0x3537 runnable [0x00007fbe2b22a000] java.lang.Thread.State: RUNNABLE at java.net.PlainSocketImpl.socketAccept(Native Method) at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:398) at java.net.ServerSocket.implAccept(ServerSocket.java:522) at java.net.ServerSocket.accept(ServerSocket.java:490) at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:388) at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:360) at java.lang.Thread.run(Thread.java:722)

"RMI TCP Accept-1099" daemon prio=10 tid=0x00007fbe3c318000 nid=0x3535 runnable [0x00007fbe2b42c000] java.lang.Thread.State: RUNNABLE at java.net.PlainSocketImpl.socketAccept(Native Method) at java.net.AbstractPlainSocketImpl.accept(AbstractPlainSocketImpl.java:398) at java.net.ServerSocket.implAccept(ServerSocket.java:522) at java.net.ServerSocket.accept(ServerSocket.java:490) at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.executeAcceptLoop(TCPTransport.java:388) at sun.rmi.transport.tcp.TCPTransport$AcceptLoop.run(TCPTransport.java:360) at java.lang.Thread.run(Thread.java:722)

"Service Thread" daemon prio=10 tid=0x00007fbe3c097800 nid=0x3533 runnable [0x0000000000000000] java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" daemon prio=10 tid=0x00007fbe3c095800 nid=0x3532 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" daemon prio=10 tid=0x00007fbe3c092800 nid=0x3531 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" daemon prio=10 tid=0x00007fbe3c090800 nid=0x3530 waiting on condition [0x0000000000000000] java.lang.Thread.State: RUNNABLE

"Finalizer" daemon prio=10 tid=0x00007fbe3c071800 nid=0x352e in Object.wait() [0x00007fbe389f8000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000078500efa8> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135) - locked <0x000000078500efa8> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:177)

"Reference Handler" daemon prio=10 tid=0x00007fbe3c06f800 nid=0x352d in Object.wait() [0x00007fbe38af9000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x000000078500ee20> (a java.lang.ref.Reference$Lock) at java.lang.Object.wait(Object.java:503) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133) - locked <0x000000078500ee20> (a java.lang.ref.Reference$Lock)

"main" prio=10 tid=0x00007fbe3c00c000 nid=0x3523 in Object.wait() [0x00007fbe44f01000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x00000007d7443208> (a java.lang.Object) at org.apache.activemq.transport.failover.FailoverTransport.oneway(FailoverTransport.java:516) - locked <0x00000007d7443208> (a java.lang.Object) at org.apache.activemq.transport.MutexTransport.oneway(MutexTransport.java:40) - locked <0x00000007d75642c8> (a java.lang.Object) at org.apache.activemq.transport.ResponseCorrelator.asyncRequest(ResponseCorrelator.java:81) at org.apache.activemq.transport.ResponseCorrelator.request(ResponseCorrelator.java:86) at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1284) at org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1392) - locked <0x00000007d75a9aa8> (a java.lang.Object) at org.apache.activemq.ActiveMQConnection.start(ActiveMQConnection.java:504) at test.ProducerConsumer.(ProducerConsumer.java:37) at test.ProducerConsumer.getInstance(ProducerConsumer.java:16) at test.ActiveMQTest.main(ActiveMQTest.java:31)

1

1 Answers

2
votes

You are creating a broker that only listens on VM transport based clients but your client is using the default connection URI which is 'failover:tcp://127.0.0.1" which means that your client will hang on start waiting for the FailoverTransport to connect to the broker. You either need to configure the connection factory to use "vm://localhost" or alter the transport connector configuration to something like:

broker.addConnector("tcp://localhost:61616");