无法启动JMS连接

时间:2014-10-08 10:04:54

标签: jms activemq

我无法启动JMS连接,其中使用ActiveMQConnectionFactory创建连接。以下是我的代码:

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

代码卡在start(),使用线程转储我可以看到下面的堆栈

  

完全线程转储Java HotSpot(TM)64位服务器VM(24.0-b28混合   模式):

     

" ActiveMQ Task-1"守护进程prio = 10 tid = 0x00007fbe3c414800 nid = 0x3543 in   Object.wait()[0x00007fbe2a715000] java.lang.Thread.State:   java.lang.Object.wait上的TIMED_WAITING(在对象监视器上)(Native   方法)      - 等待< 0x00000007d7443228> (java.lang.Object)org.apache.activemq.transport.failover.FailoverTransport.doReconnect(FailoverTransport.java:954)      - 已锁定< 0x00000007d7443228> (java.lang.Object)org.apache.activemq.transport.failover.FailoverTransport $ 2.iterate(FailoverTransport.java:136)      - 已锁定< 0x00000007d7443218> (java.lang.Object)org.apache.activemq.thread.PooledTaskRunner.runTask(PooledTaskRunner.java:127)     在   org.apache.activemq.thread.PooledTaskRunner $ 1.run(PooledTaskRunner.java:48)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:603)     在java.lang.Thread.run(Thread.java:722)

     

" ActiveMQConnection [ID:ayush-0791-50867-1412762440207-2:1]调度程序"   Object.wait()中的守护程序prio = 10 tid = 0x00007fbe3c413000 nid = 0x3542   [0x00007fbe2a816000] java.lang.Thread.State:WAITING(在对象上   监视器)在java.lang.Object.wait(本机方法)      - 等待< 0x00000007d75d73a8> java.lang.Object.wait(Object.java:503)at(java.util.TaskQueue)at at   java.util.TimerThread.mainLoop(Timer.java:526)      - 已锁定< 0x00000007d75d73a8> java.util.TimerThread.run上的(java.util.TaskQueue)(Timer.java:505)

     

" ActiveMQ Broker [localhost]调度程序"守护进程prio = 10   Object.wait()中的tid = 0x00007fbe3c3e0000 nid = 0x3541   [0x00007fbe2a917000] java.lang.Thread.State:TIMED_WAITING(on   对象监视器)在java.lang.Object.wait(本机方法)      - 等待< 0x00000007d93fa080> (java.util.TaskQueue)java.util.TimerThread.mainLoop(Timer.java:552)      - 已锁定< 0x00000007d93fa080> java.util.TimerThread.run上的(java.util.TaskQueue)(Timer.java:505)

     

" ActiveMQ数据文件编写器"守护进程prio = 10 tid = 0x00007fbe3c3d1800   Object.wait()[0x00007fbe2aa18000]中的nid = 0x3540   java.lang.Thread.State:WAITING(在对象监视器上)at   java.lang.Object.wait(Native方法)      - 等待< 0x00000007d93fa3b8> (一个org.apache.kahadb.journal.DataFileAppender $ 1)at   java.lang.Object.wait(Object.java:503)at   org.apache.kahadb.journal.DataFileAppender.processQueue(DataFileAppender.java:312)      - 已锁定< 0x00000007d93fa3b8> (一个org.apache.kahadb.journal.DataFileAppender $ 1)at   org.apache.kahadb.journal.DataFileAppender $ 2.run(DataFileAppender.java:203)

     

" ActiveMQ Journal Checkpoint Worker"守护进程prio = 10   tid = 0x00007fbe3c3cb000 nid = 0x353f等待条件   [0x00007fbe2ab19000] java.lang.Thread.State:TIMED_WAITING   (睡觉)在java.lang.Thread.sleep(Native Method)at   org.apache.activemq.store.kahadb.MessageDatabase $ 3.run(MessageDatabase.java:296)

     

" KahaDB Scheduler"守护进程prio = 10 tid = 0x00007fbe3c3c1000 nid = 0x353e in   Object.wait()[0x00007fbe2b32b000] java.lang.Thread.State:   java.lang.Object.wait上的TIMED_WAITING(在对象监视器上)(Native   方法)      - 等待< 0x00000007d981f418> (java.util.TaskQueue)java.util.TimerThread.mainLoop(Timer.java:552)      - 已锁定< 0x00000007d981f418> java.util.TimerThread.run上的(java.util.TaskQueue)(Timer.java:505)

     

" RMI RenewClean- [192.168.57.33:47976]"守护进程prio = 10   Object.wait()中的tid = 0x00007fbde0005800 nid = 0x353c   [0x00007fbe2ad1b000] java.lang.Thread.State:TIMED_WAITING(on   对象监视器)在java.lang.Object.wait(本机方法)      - 等待< 0x00000007d9889870> (一个java.lang.ref.ReferenceQueue $ Lock)at   java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)      - 已锁定< 0x00000007d9889870> (一个java.lang.ref.ReferenceQueue $ Lock)at   sun.rmi.transport.DGCClient $ EndpointEntry $ RenewCleanThread.run(DGCClient.java:535)     在java.lang.Thread.run(Thread.java:722)

     

" RMI调度程序(0)"守护进程prio = 10 tid = 0x00007fbdf0024800 nid = 0x353b   等待条件[0x00007fbe2ae1c000] java.lang.Thread.State:   在sun.misc.Unsafe.park(原生方法)的TIMED_WAITING(停车)      - 停车等待< 0x00000007850ffb10> (java.util.concurrent.locks.AbstractQueuedSynchronizer $ ConditionObject)     在   java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)     在   java.util.concurrent.locks.AbstractQueuedSynchronizer中的$ ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2082)     在   java.util.concurrent.ScheduledThreadPoolExecutor中的$ DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1090)     在   java.util.concurrent.ScheduledThreadPoolExecutor中的$ DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:807)     在   java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)     在   java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)     在   java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:603)     在java.lang.Thread.run(Thread.java:722)

     

" GC守护进程" daemon prio = 10 tid = 0x00007fbdf0006800 nid = 0x3539 in   Object.wait()[0x00007fbe2b028000] java.lang.Thread.State:   java.lang.Object.wait上的TIMED_WAITING(在对象监视器上)(Native   方法)      - 等待< 0x00000007850069b0> (sun.misc.GC $ LatencyLock)sun.misc.GC $ Daemon.run(GC.java:117)      - 已锁定< 0x00000007850069b0> (一个sun.misc.GC $ LatencyLock)

     

" RMI Reaper" prio = 10 tid = 0x00007fbdf0004800 nid = 0x3538 in   Object.wait()[0x00007fbe2b129000] java.lang.Thread.State:WAITING   (在对象监视器上)java.lang.Object.wait(Native Method)      - 等待< 0x0000000785000b98> (一个java.lang.ref.ReferenceQueue $ Lock)at   java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)      - 已锁定< 0x0000000785000b98> (java.lang.ref.ReferenceQueue $ Lock)在java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)at at   sun.rmi.transport.ObjectTable $ Reaper.run(ObjectTable.java:351)at at   java.lang.Thread.run(Thread.java:722)

     

" RMI TCP Accept-0"守护进程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)     在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)     在   sun.rmi.transport.tcp.TCPTransport $ AcceptLoop.run(TCPTransport.java:360)     在java.lang.Thread.run(Thread.java:722)

     

" RMI TCP Accept-1099"守护进程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)     在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)     在   sun.rmi.transport.tcp.TCPTransport $ AcceptLoop.run(TCPTransport.java:360)     在java.lang.Thread.run(Thread.java:722)

     

"服务主题"守护进程prio = 10 tid = 0x00007fbe3c097800 nid = 0x3533   runnable [0x0000000000000000] java.lang.Thread.State:RUNNABLE

     

" C2 CompilerThread1"守护进程prio = 10 tid = 0x00007fbe3c095800 nid = 0x3532   等待条件[0x0000000000000000] java.lang.Thread.State:   RUNNABLE

     

" C2 CompilerThread0"守护进程prio = 10 tid = 0x00007fbe3c092800 nid = 0x3531   等待条件[0x0000000000000000] java.lang.Thread.State:   RUNNABLE

     

" Signal Dispatcher"守护进程prio = 10 tid = 0x00007fbe3c090800 nid = 0x3530   等待条件[0x0000000000000000] java.lang.Thread.State:   RUNNABLE

     

"终结"守护进程prio = 10 tid = 0x00007fbe3c071800 nid = 0x352e in   Object.wait()[0x00007fbe389f8000] java.lang.Thread.State:WAITING   (在对象监视器上)java.lang.Object.wait(Native Method)      - 等待< 0x000000078500efa8> (一个java.lang.ref.ReferenceQueue $ Lock)at   java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)      - 已锁定< 0x000000078500efa8> (java.lang.ref.ReferenceQueue $ Lock)在java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)at at   java.lang.ref.Finalizer $ FinalizerThread.run(Finalizer.java:177)

     

"参考处理程序"守护进程prio = 10 tid = 0x00007fbe3c06f800 nid = 0x352d   在Object.wait()[0x00007fbe38af9000] java.lang.Thread.State:   在java.lang.Object.wait上等待(在对象监视器上)(本机方法)      - 等待< 0x000000078500ee20> java.lang.Object.wait(Object.java:503)at(java.lang.ref.Reference $ Lock)at at   java.lang.ref.Reference中的$ ReferenceHandler.run(Reference.java:133)      - 已锁定< 0x000000078500ee20> (java.lang.ref.Reference $ Lock)

     

"主" Object.wait()中的prio = 10 tid = 0x00007fbe3c00c000 nid = 0x3523   [0x00007fbe44f01000] java.lang.Thread.State:TIMED_WAITING(on   对象监视器)在java.lang.Object.wait(本机方法)      - 等待< 0x00000007d7443208> (java.lang.Object)org.apache.activemq.transport.failover.FailoverTransport.oneway(FailoverTransport.java:516)      - 已锁定< 0x00000007d7443208> (java.lang.Object)org.apache.activemq.transport.MutexTransport.oneway(MutexTransport.java:40)      - 已锁定< 0x00000007d75642c8> (java.lang.Object)org.apache.activemq.transport.ResponseCorrelator.asyncRequest(ResponseCorrelator.java:81)     在   org.apache.activemq.transport.ResponseCorrelator.request(ResponseCorrelator.java:86)     在   org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1284)     在   org.apache.activemq.ActiveMQConnection.ensureConnectionInfoSent(ActiveMQConnection.java:1392)      - 已锁定< 0x00000007d75a9aa8> (java.lang.Object)org.apache.activemq.ActiveMQConnection.start(ActiveMQConnection.java:504)     在test.ProducerConsumer。(ProducerConsumer.java:37)at   test.ProducerConsumer.getInstance(ProducerConsumer.java:16)at   test.ActiveMQTest.main(ActiveMQTest.java:31)

1 个答案:

答案 0 :(得分:2)

您正在创建仅侦听基于VM传输的客户端的代理,但您的客户端使用的默认连接URI是“故障转移:tcp://127.0.0.1"这意味着您的客户端将在等待FailoverTransport连接到代理时挂起。您需要将连接工厂配置为使用" vm:// localhost"或将传输连接器配置更改为:

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