Skip to content

Instantly share code, notes, and snippets.

@jfarcand
Created May 31, 2010 19:50
Show Gist options
  • Save jfarcand/420199 to your computer and use it in GitHub Desktop.
Save jfarcand/420199 to your computer and use it in GitHub Desktop.
public class AsyncServlet implements AtmosphereHandler<HttpServletRequest, HttpServletResponse> {
@Override
public void onRequest(AtmosphereResource<HttpServletRequest,HttpServletResponse> resource)
throws ServletException, IOException {
try {
System.out.println("Starting onRequest");
resource.suspend();
// Will be executed using a ScheduledThreadPool (can also use scheduleBroadcast)
resource.delayBroadcast("Something",10, TimeUnit.SECONDS);
} finally {
}
}
@Override
public void onStateChange(AtmosphereResourceEvent<HttpServletRequest,HttpServletResponse> event) {
if (!event.isResuming() && !event.isCancelled()) {
event.resume();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment