Skip to content

Instantly share code, notes, and snippets.

@derekbassett
Created November 13, 2014 17:32
Show Gist options
  • Save derekbassett/cd0dbc261a49a451657a to your computer and use it in GitHub Desktop.
Save derekbassett/cd0dbc261a49a451657a to your computer and use it in GitHub Desktop.
Simple instructions on how to add an Async Servlet to an Embedded Tomcat
public class Main {
private static final int PORT = 8085;
public static void main(String args[]){
Tomcat server = new Tomcat();
server.setPort(PORT);
Context ctx = server.addContext("/ctx0", new File(".").getAbsolutePath());
Wrapper wrapper = Tomcat.addServlet(ctx, "MyAsyncServlet", new MyAsyncServlet());
// Have to set Async supported on this servlet since we are not using annotations.
wrapper.setAsyncSupported(true);
ctx.addServletMapping("/*", "MyAsyncServlet");
server.start();
// Wait for some condition and then stop
server.stop();
}
}
@derekbassett
Copy link
Author

There are many examples on the web on how to create a Tomcat Servlet using an embedded Tomcat but none on how to create an async servlet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment