title: Tomcat, Comet and getOutputStream() has already been called for this response
body: <p>I am using Tomcat 6.0.32 with the Http11NioProtocol connector to implement long polling.</p>
  
  <p>My comet processor is holding the <code>HttpSevletResponse</code> on a queue until an event is ready to send back. When it sends back the event it is writing a binary stream to an applet, so I use <code>response.getOutputStream().write()</code> to send data back. When writing to the stream it is synchronized.</p>
  
  <p>When another web page in a second frame reloads (Independent JSP generated from SpringController in same container) occasionally I see this in the logs and the page fails to load.</p>
  
  <p>Is it possible there is a concurrency error between a response generated from a comet processor and a regular servlet when both are requested at the same time?</p>
  
  <p>The stack trace:</p>
  
  <pre><code>java.lang.IllegalStateException: getOutputStream() has already been called for this response
  at org.apache.catalina.connector.Response.getWriter(Response.java:611)
  at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198)
  at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
  at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
  at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:112)
  at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
  at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
  at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:180)
  at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118)
  at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:77)
  at org.apache.jsp.WEB_002dINF.jsp.sale_jsp._jspService(sale_jsp.java:96)
  </code></pre>