-
1. Re: Reccommended JMS reconnect pattern not working for me
adrian.brock Feb 9, 2005 7:37 PM (in response to mjgreene550)If the connection has failed, connection.stop() will throw an exception.
This will bypass your close() and reconnect and jump straight to the exception
handler.
close() does a stop() anyway so it is redundant.
I'd also recommend you spawn a thread to do the reconnect.
If a reconnect is not immediately possible, you can doboolean reconnected = false; while (reconnected == false) { try { reconnect(); reconnected = true; } catch (Throwable t) { disconnect(); // handles reconnect failing part way through t.printStackTrace(); } if (reconnected == false) Thread.sleep(10000); // wait ten seconds before trying again }
You can run the same routine to connect at startup,
if your application starts with no jms server available. -
2. Re: Reccommended JMS reconnect pattern not working for me
adrian.brock Feb 9, 2005 7:39 PM (in response to mjgreene550)The one thing you need to avoid is a "fork bomb" where
setExceptionListener() gets invoked during reconnect().
This is usually be handled by some synchronized state that
says don't fork another thread if you already have some thread
in the reconnect loop. -
3. Re: Reccommended JMS reconnect pattern not working for me
mjgreene550 Feb 9, 2005 10:49 PM (in response to mjgreene550)Hey Adrian,
Thanks for the logic. That actually helped me get my topic reconnected correctly. Unforuantely I still get these damn exceptions:22:45:17,921 WARN [Connection] Connection failure: org.jboss.mq.SpyJMSException: Connection Failed; - nested throwable: (java.io.IOException: ping timeout.) at org.jboss.mq.Connection.asynchFailure(Connection.java:436) at org.jboss.mq.Connection$PingTask.run(Connection.java:1385) at EDU.oswego.cs.dl.util.concurrent.ClockDaemon$RunLoop.run(ClockDaemon.java:364) at java.lang.Thread.run(Thread.java:534) Caused by: java.io.IOException: ping timeout. at org.jboss.mq.Connection$PingTask.run(Connection.java:1377) ... 2 more
I did however want to post how I did my reconnection logic specifically in case anyone else was interested:private class TopicConnectionListener implements ExceptionListener { public void onException(JMSException ex) { connected = false; try { topicConnection.close(); } catch (JMSException e) { e.printStackTrace(); } if (!reconnecting) { new SimpleThread("JMS Reconnection Thread").start(); } } } private class SimpleThread extends Thread { public SimpleThread(String str) { super(str); } public void run() { reconnecting = true; while (!connected) { //reconnect subscribeToTreeTopic(); if (!connected) { try { Thread.sleep(10000); } catch (InterruptedException e) { e.printStackTrace(); } } } reconnecting = false; } }
What I do is when I initially connect my topic, I invoke this line:topicConnection.setExceptionListener(new TopicConnectionListener());
-
4. Re: Reccommended JMS reconnect pattern not working for me
adrian.brock Feb 10, 2005 1:16 PM (in response to mjgreene550)I cannot help you any further since you have hidden all the jms invocations
inside methods you do not show.
Also use "READ THIS FIRST" to enable logging. It will tell you in *painful* detail
what is happening to the connection, i.e. when it is opened, when it is closed,
when the ping occurs, when the ping task is removed, etc.