Created
March 13, 2015 10:52
-
-
Save abhirockzz/e892ac81c6c30396f80f to your computer and use it in GitHub Desktop.
JAX-RS async time out
This file contains 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
@GET | |
@Produces("text/plain") | |
public void execute(@Suspended AsyncResponse response){ | |
System.out.println("Initially invoked on thread - "+ Thread.currentThread.getName() + ". This will free up soon !"); | |
//just having this would result in HTTP 503 after 10 seconds | |
response.setTimeout(10, TimeUnit.SECONDS); | |
//client will recieve a HTTP 408 (timeout error) after 10 seconds | |
response.setTimeoutHandler((asyncResp) -> asyncResp.resume(Response.status(Response.Status.REQUEST_TIMEOUT)).build()); | |
new Thread(() -> { | |
try { | |
Thread.sleep(11000); | |
} catch (InterruptedException ex) { | |
//ignoring | |
} | |
}).start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment