@@ -58,12 +58,15 @@ public class JMSReader {
58
58
59
59
private RecordBuilder builder ;
60
60
61
- private boolean connected = false ; // Whether connected to MQ
62
- private boolean inflight = false ; // Whether messages in-flight in current transaction
63
- private boolean inperil = false ; // Whether current transaction must be forced to roll back
64
- private AtomicBoolean closeNow = new AtomicBoolean (); // Whether close has been requested
61
+ private boolean connected = false ; // Whether connected to MQ
62
+ private boolean inflight = false ; // Whether messages in-flight in current transaction
63
+ private boolean inperil = false ; // Whether current transaction must be forced to roll back
64
+ private AtomicBoolean closeNow = new AtomicBoolean (); // Whether close has been requested
65
+ private long reconnectDelayMillis = RECONNECT_DELAY_MILLIS_MIN ; // Delay between repeated reconnect attempts
65
66
66
67
private static long RECEIVE_TIMEOUT = 30000l ;
68
+ private static long RECONNECT_DELAY_MILLIS_MIN = 64l ;
69
+ private static long RECONNECT_DELAY_MILLIS_MAX = 8192l ;
67
70
68
71
public JMSReader () {}
69
72
@@ -297,11 +300,25 @@ private boolean connectInternal() {
297
300
}
298
301
299
302
jmsCons = jmsCtxt .createConsumer (queue );
303
+ reconnectDelayMillis = RECONNECT_DELAY_MILLIS_MIN ;
300
304
connected = true ;
301
305
302
306
log .info ("Connection to MQ established" );
303
307
}
304
308
catch (JMSRuntimeException jmse ) {
309
+ // Delay slightly so that repeated reconnect loops don't run too fast
310
+ try {
311
+ Thread .sleep (reconnectDelayMillis );
312
+ }
313
+ catch (InterruptedException ie ) {
314
+ ;
315
+ }
316
+
317
+ if (reconnectDelayMillis < RECONNECT_DELAY_MILLIS_MAX )
318
+ {
319
+ reconnectDelayMillis = reconnectDelayMillis * 2 ;
320
+ }
321
+
305
322
log .error ("JMS exception {}" , jmse );
306
323
handleException (jmse );
307
324
log .trace ("[{}] Exit {}.connectInternal, retval=false" , Thread .currentThread ().getId (), this .getClass ().getName ());
0 commit comments