线程在producer.send()之后挂起

时间:2013-12-05 16:22:13

标签: java multithreading glassfish jms

我编写了以下代码来向消费者发送消息。它可以在消费者活着的时候工作。但我正在测试如果消费者失败会发生什么。所以我有以下课程。

public class MyConnection{
Producer producer;

private void init(String brokerAddress){
     com.sun.messaging.ConnectionFactory myFactory = new com.sun.messaging.ConnectionFactory();
     myFactory.setProperty(ConnectionConfiguration.imqAddressList, brokerAddress);
     myFactory.setProperty(ConnectionConfiguration.imqAckOnProduce, "false");
     myFactory.setProperty(ConnectionConfiguration.imqConfiguredClientID, "clientId");
     myFactory.setProperty(ConnectionConfiguration.imqEnableSharedClientID, "true");
     javax.jms.Connection conn = myFactory.createConnection();
     session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
     this.producer = session.createProducer(session.createTopic("SOME_TOPIC"));
     myFactory.getProperty(ConnectionConfiguration.imqAckOnProduce);
     connectionStatus = BROKER_CONNECTED;
}
//Message is of type javax.jms.Message  
private send(Message message){
  boolean paramterSent = false;
  try
  {
     producer.send(message);
     paramterSent = true;
  }
  catch (JMSException e)
  {
     connectionStatus = BROKER_DISCONNECTED;
     logger.log(Level.INFO, "Could not send message to EPS ", e);
  }
  return paramterSent;
}

所以我在这里测试的是我正在调用init()并创建连接然后我正在杀死收到消息的代理。然后我试图调用发送所以我希望它抛出和JMXException,但它没有,它挂在producer.send()和控制台上我收到此消息。

Dec 5, 2013 9:14:54 AM com.sun.messaging.jmq.jmsclient.ExceptionHandler logCaughtException
WARNING: [I500]: Caught JVM Exception: java.io.EOFException: Trying to read 72 bytes. Already read 0 bytes.
Dec 5, 2013 9:14:57 AM com.sun.messaging.jmq.jmsclient.ConnectionRecover logRecoverState
INFO: [I107]: Connection recover state: RECOVER_INACTIVE, broker: localhost:31300(31301)
Dec 5, 2013 9:15:21 AM com.sun.messaging.jmq.jmsclient.ExceptionHandler throwConnectionException
WARNING: [C4003]: Error occurred on connection creation [10.187.37.188:31300]. - cause: java.net.ConnectException: Connection timed out: connect

我正在使用以下

Oracle GlassFish(tm) Server MQ Destination
getName():      SOME_TOPIC
Class:          com.sun.messaging.BasicTopic
getVERSION():       3.0
isReadonly():       false
getProperties():    {imqDestinationName=SOME_TOPIC, imqDestinationDescription=A Description for the Destination Object}

我从投资中发现的是,在com.sun.messaging.jmq.jmsclient.MessageProducerImpl类中,checkReconnecting方法无法锁定对象reconnectSyncObj,所以它试图访问它但不能如此悬挂。有什么想法吗?

谢谢, 斯利拉姆

1 个答案:

答案 0 :(得分:0)

我通过在代理断开连接时关闭连接来解决问题。我是在javax.jms.ExceptionListener的onException方法中完成的。

 public void onException(JMSException exception)
      {
         try
         {
            connection.close();
         }
         catch (JMSException e)
         {
            logger.log(Level.INFO, "Connection Failed", e);
         }
      }