Skip to content

Instantly share code, notes, and snippets.

@abhirockzz
Created November 14, 2016 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhirockzz/6efef2084f7dcf632e8345de009b385c to your computer and use it in GitHub Desktop.
Save abhirockzz/6efef2084f7dcf632e8345de009b385c to your computer and use it in GitHub Desktop.
WebSocket time out using (java.util.concurrent) Future
....
public void broadcast(Session s, String msg){
RemoteEndpoint asyncHandle = s.getRemoteAsync();
asyncHandle.setSendTimeout(2000); //2000 ms
Future<Void> tracker = asyncHandle.sendText(msg); //will timeout after 2 seconds
tracker.get(); //will throw java.util.ExecutionException if the process had timed out
}
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment