users@glassfish.java.net

Servlet 3.0 (GF3) async doPost time lag

From: <glassfish_at_javadesktop.org>
Date: Thu, 13 May 2010 07:34:50 PDT

I am trying to write a 3.0 servlet (Glassfish v3) with an async processing for both doGet and doPost.

Have no problems with doGet but doPost displays strange behavior:
almost every consecutive call results in 30sec time lag before the server sends a response. Calling doGet after a suspended doPost results in the same delay as well. It looks like the container doesn't release the resource or maybe I am missing something...

Do you have any ideas what can cause this?

Here's my simple servlet.

package app;

import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;

@WebServlet(urlPatterns = "/app", asyncSupported = true)
public class AppOne extends HttpServlet {
   
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        final AsyncContext actx = req.startAsync(req, res);
        actx.start(new Runnable() {

            public void run() {
                try {
                    HttpServletResponse res = (HttpServletResponse)actx.getResponse();
                    res.setContentType("text/plain");
                    PrintWriter out = res.getWriter();
                    out.println("doGet-async");
                    out.flush();
                } catch (IOException ex) {
                    System.err.println(ex.getMessage());
                } finally {
                    System.out.println("doGet ASYNC FINISHED");
                    actx.complete();
                }
            }
        });
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        System.out.println("doPost");
        final AsyncContext actx = req.startAsync(req, res);
        actx.start(new Runnable() {

            public void run() {
                try {
                    HttpServletResponse res = (HttpServletResponse)actx.getResponse();
                    res.setContentType("text/plain");
                    res.setHeader("Cache-Control", "private");
                    res.setHeader("Pragma", "no-cache");

                    PrintWriter out = res.getWriter();
                    out.println("doPost-async");
                    out.flush();
                } catch (IOException ex) {
                    System.err.println(ex.getMessage());
                } finally {
                    System.out.println("doPost ASYNC FINISHED");
                    actx.complete();
                }
            }
        });
        
    }
}

The servlet gets called from index.html with a form:

    <form method="post" action="/exSimpleAsync/app">
        <input type="text" size="20" name="email" value="hello">
        <input type="submit" name="login" value="Click me">
    </form>
[Message sent by forum member 'denisz']

http://forums.java.net/jive/thread.jspa?messageID=469695