https://issues.apache.org/bugzilla/show_bug.cgi?id=54571

David Wang <david.f.w...@alcatel-lucent.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #3 from David Wang <david.f.w...@alcatel-lucent.com> ---
(In reply to comment #2)
> This looks like an application problem.
> 
> As the Comet docs state, the Response object is not thread safe.
> 
> By using a separate thread to write to the response you have multiple
> threads (the original request processing thread and your processing thread)
> using the object at the same time. It is not surprising that strange
> behaviour is observed.

But the demo code for comet on tomcat webpage has similar logic
http://tomcat.apache.org/tomcat-6.0-doc/aio.html

Servelet thread:
-----------------
if (event.getEventType() == CometEvent.EventType.BEGIN) {
            log("Begin for session: " + request.getSession(true).getId());
            PrintWriter writer = response.getWriter();
            writer.println("<!doctype html public \"-//w3c//dtd html 4.0
transitional//en\">");
            writer.println("<head><title>JSP Chat</title></head><body
bgcolor=\"#FFFFFF\">");
            writer.flush();
            synchronized(connections) {
                connections.add(response);
            }

Other thread:
----------------
for (int i = 0; i < connections.size(); i++) {
                        try {
                            PrintWriter writer =
connections.get(i).getWriter();
                            for (int j = 0; j < pendingMessages.length; j++) {
                                writer.println(pendingMessages[j] + "<br>");
                            }
                            writer.flush();
                        } catch (IOException e) {
                            log("IOExeption sending message", e);
                        }
                    }

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to