/**
 * 
 */
package jetty.async.test;

import java.io.IOException;

import javax.servlet.AsyncContext;
import javax.servlet.AsyncEvent;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Issues an async write with contentlength != bytes writte before
 * 
 * @author Christoph Läubrich
 */
public class TimeoutWriteListenerServlet extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = 3431896464670815605L;
    /**
     * 
     */
    private static final int  WRITE_CHARS      = 10000;

    /* (non-Javadoc)
     * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Request: " + req.getRequestURI());
        resp.setContentLength(Integer.MAX_VALUE);
        final AsyncContext async = req.startAsync();
        async.setTimeout(1);
        async.addListener(new DebugAsyncListener() {
            @Override
            public void onTimeout(AsyncEvent event) throws IOException {
                super.onTimeout(event);
                async.complete();
            }
        });
        final byte[] responsebytes = new byte[WRITE_CHARS - 10];
        for (int i = 0; i < responsebytes.length; i++) {
            if (i > 0 && i % 100 == 0) {
                responsebytes[i] = '\n';
            } else {
                responsebytes[i] = (byte) (48 + (Math.random() * 74));
            }
        }
        final ServletOutputStream stream = resp.getOutputStream();
        stream.setWriteListener(new DebugWriteListener() {

            @Override
            public void onWritePossible() throws IOException {
                super.onWritePossible();
                while (stream.isReady()) {
                    //write endlessly...
                    stream.write(responsebytes);
                }
                System.out.println("Stream is not ready...");
            }

        });
    }
}

@@ -59,16 +59,54 @@
 ception;
+%0Aimport java.util.concurrent.TimeUnit;
 %0A%0Aimport
@@ -1206,17 +1206,44 @@
 Timeout(
-1
+TimeUnit.SECONDS.toMillis(1)
 );%0A     

Use 1 second timeout