Skip to content
Advertisement

Tag: timeout

Does Spring AMQP CorrelationData getFuture wait indefinitely without timeout?

In the context of Publisher confirms, when waiting for the CorrelationData’s future (SettableListenableFuture#get()) – does it wait indefinitely or is there a timeout configured under the water? Answer It does wait indefinitely. There is just no any opinion and everything is delegated directly to the java.util.concurrent.FutureTask internally in the org.springframework.util.concurrent.SettableListenableFuture implementation. Not sure why the question, but in normal situation

Java: set timeout on a certain block of code?

Is it possible to force Java to throw an Exception after some block of code runs longer than acceptable? Answer Yes, but its generally a very bad idea to force another thread to interrupt on a random line of code. You would only do this if you intend to shutdown the process. What you can do is to use Thread.interrupt()

HttpURLConnection timeout settings

I want to return false if the URL takes more then 5 seconds to connect – how is this possible using Java? Here is the code I am using to check if the URL is valid Answer HttpURLConnection has a setConnectTimeout method. Just set the timeout to 5000 milliseconds, and then catch java.net.SocketTimeoutException Your code should look something like this:

Advertisement