I'm new to JavaEE 6 and I learnt that it support asynchronous servlets called AsyncServlets. So I tried to create a small program using JavaEE6.
Here is my code for the servlet
@WebServlet(name = "AsyncServlet", urlPatterns = {"/AsyncServlet"}, asyncSupported=true)
public class AsyncServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
AsyncContext aCtx = request.startAsync(request, response);
Executor executor = Executors.newSingleThreadExecutor();
executor.execute(new MyClass(aCtx));
System.out.println("Original thread is freed");
}
}
But when I try to run the servlet I get an exception java.lang.IllegalStateException: Not supported. I'm using tomcat 7.0.14 as the server. i did not create a web.xml. Where is the problem in this code?
EDIT:
This is the full stack-trace of the exception
SEVERE: Servlet.service() for servlet [AsyncServlet] in context with path [/AsyncTest] threw exception
java.lang.IllegalStateException: Not supported.
at org.apache.catalina.connector.Request.startAsync(Request.java:1618)
at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1031)
at javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:379)
at com.icbt.demo.servlet.AsyncServlet.doGet(AsyncServlet.java:30)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
if you use tomcat as your web server then you should maintion that you are going to use asyc request to tomcat
before start async request put this line code
request.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
i hope you can get what u want from it
An IllegalStateException will be thrown if an application tries to start an asynchronous operation and there is a servlet or servlet filter in the request processing chain that does not support asynchronous processing.So there might be have some mistake.plz check your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With