0

I'm implementing HTTP Streaming servlet to deliver push notifications to client. In that container there is also Jersey JAX-RS REST service.

The problem is when I open the stream in two browser windows I have to wait until the other request is completed.

I read the similar topic Servlet seems to handle multiple concurrent browser requests synchronously and opened the stream in two different browsers the stream and got it work.

And I tried to use AsyncContext, but it not stream, it allow to open browser tabs concurrently and at the end of execution thread delivers all the content to browser.

Also I tried to open concurrently the sample JSP page in two browser tabs and got similar result.

    <HTML>
    <HEAD>
       <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
       <meta http-equiv="Pragma" content="no-cache">
    </HEAD>
    <BODY BGCOLOR="blue" TEXT="white">
    <% 
      try {
        for (int i=1; i < 100; i++) {
           out.print("<h1>"+i+"</h1>");
           out.flush();

           try {
                Thread.sleep(1000);
           } catch (InterruptedException e) {
                out.print("<h1>"+e+"</h1>");
           }
         }
       } catch (Exception e) {
           out.print("<h1>"+e+"</h1>");
       }
       out.print("<h1>DONE</h1>");
    %>
    </BODY>
    </HTML>

As server I'm using Apache Tomcat 7.0. But use another servlet container wouldn't be a problem.

Any pointers?

Thanks

Community
  • 1
  • 1
ik1
  • 213
  • 3
  • 14

1 Answers1

0

Doing your own thread management from a servlet container is almost never a good idea.

For server push in Tomcat see here: http://tomcat.apache.org/tomcat-7.0-doc/aio.html

Are you sure client-side polling wouldn't be easier, though?

Dmitri
  • 8,999
  • 5
  • 36
  • 43
  • I've done as instruction told, removed doGet method and implemented CometProcessor interface, removed infinite while loop and set NIO connector instead of default HTTP. And implemented event method like: public void event(CometEvent event) throws IOException, ServletException { if (event.getEventType() == CometEvent.EventType.BEGIN) { Here is my subscription logic... } } It works, but nothing changed. – ik1 Jan 11 '14 at 12:17