Skip to content

Instantly share code, notes, and snippets.

@rhyskeepence
Created November 24, 2010 10:57
Show Gist options
  • Save rhyskeepence/713483 to your computer and use it in GitHub Desktop.
Save rhyskeepence/713483 to your computer and use it in GitHub Desktop.
Print a message if connecting is taking too long
private void attachListener() {
ScheduledFuture<?> activemqWarning = scheduleWarningIfJmsConnectionTakesTooLong();
try {
// perform some operation that may hang if ActiveMq is not running
} finally {
activemqWarning.cancel(true);
}
}
private ScheduledFuture<?> scheduleWarningIfJmsConnectionTakesTooLong() {
return Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {
public void run() {
System.err.println("WARNING: It's taking a long time to connect to JMS - check ActiveMQ is running!");
}
}, 10, TimeUnit.SECONDS);
}
@rhyskeepence
Copy link
Author

Setting a failover timeout means my app quits. I'd rather see a warning and be able to start activemq without restarting my app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment