jboss 5.1、Javaスタンドアロンアプリケーションを使用します。
スタンドアロンアプリケーションからjbossjmsへのメッセージをリッスンしようとしています。
問題は、jbossサーバーを強制終了すると、スタンドアロンアプリケーション側で例外が発生しますが、receive()がハングするため、スレッドがスタックし、再接続または他の操作を実行できません。
それは私のスタンドアロンの例外です:
2012-05-31 11:47:18,738 org.jboss.remoting.transport.socket.SocketClientInvoker [ERROR] Got marshalling exception, exiting
java.io.IOException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.BufferedOutputStream.flushBuffer(Unknown Source)
at java.io.BufferedOutputStream.flush(Unknown Source)
at java.io.DataOutputStream.flush(Unknown Source)
at org.jboss.jms.wireformat.SerializedPacket.write(SerializedPacket.java:81)
at org.jboss.jms.wireformat.JMSWireFormat.write(JMSWireFormat.java:237)
at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.versionedWrite(MicroSocketClientInvoker.java:971)
at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:606)
at org.jboss.remoting.transport.bisocket.BisocketClientInvoker.transport(BisocketClientInvoker.java:418)
at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:122)
at org.jboss.remoting.ConnectionValidator.doCheckConnectionWithLease(ConnectionValidator.java:522)
at org.jboss.remoting.ConnectionValidator.run(ConnectionValidator.java:301)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
私のスタンドアロンアプリケーションコード:
private static Logger log = LoggerFactory.getLogger(MomTopicListenerAbs.class);
protected String componentCode = null;
protected int reconnectTimeInterval = 30000;
MessageConsumer topicMsgConsumer = null;
Session topicSession = null;
String momUrl = null;
Connection topicConnection = null;
InitialContext jmsContext = null;
private Thread listenerThread = null;
boolean shouldListen = true;
@Override
public void connectToTopic() throws Exception
{
TopicConnectionFactory myConnFactory;
Topic myTopic;
String MYCF_LOOKUP_NAME = MomConstants.MOM_EXTERNAL_CONNECTION_FACTORY;
String MYTOPIC_LOOKUP_NAME = MomConstants.DISPATCHER_TOPIC_LOOKUP;
jmsContext = new InitialContext();
jmsContext.addToEnvironment("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
jmsContext.addToEnvironment("java.naming.factory.url.pkgs", "org.jnp.interfaces");
jmsContext.addToEnvironment(Context.PROVIDER_URL, momUrl);
myConnFactory = (javax.jms.TopicConnectionFactory) jmsContext.lookup(MYCF_LOOKUP_NAME);
myTopic = (Topic) jmsContext.lookup(MYTOPIC_LOOKUP_NAME);
topicConnection = myConnFactory.createConnection();
topicSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
topicMsgConsumer = topicSession.createConsumer(myTopic);
topicConnection.start();
}
@Override
public void run()
{
Message msg = null;
log.info("Listening to Mom Topic at url=" + momUrl + " started.");
try
{
connectToTopic();
while (shouldListen)
{
try
{ //this is where it hangs when I kill the jboss server.
msg = topicMsgConsumer.receive();
if (msg == null)
{
throw new Exception("Received empty msg from Topic Listener. could be caused by stopListening() invoke");
}
executeMsgThread(msg);
}
catch (JMSException e)
{
log.error("Caught JMS exception, reconnecting...", e);
}
catch (Exception e)
{
log.error("Error in topic Listener. errorMsg=" + e.getMessage(), e);
}
}
}
catch (Throwable t)
{
log.error(TAG + ", System error", t);
}
どうすればその例外をキャッチできますか?
ありがとう、レイ。