Created
November 24, 2010 10:57
-
-
Save rhyskeepence/713483 to your computer and use it in GitHub Desktop.
Print a message if connecting is taking too long
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
You could just this from the URL used to connect the ActiveMQ broker - see http://activemq.apache.org/failover-transport-reference.html for information on setting failover timeouts.
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
ActiveMq client code hangs if the server is not up. It would be helpful if we knew that is why it is hanging.
So, schedule a thread to print a message if we can't connect within 10 seconds.