Makes perfect sense. Unfortunately, I'm using tomcat 6 / JBoss 4. Updating to J2EE 6 is probably going to be a huge task.
I think I'll have to strip out my use of the request/response/session from my async code. Thanks Mark! -d On Sat, Aug 31, 2013 at 2:50 PM, Mark Thomas <ma...@apache.org> wrote: > Darrell Esau <darrell.e...@gmail.com> wrote: > >Hi all, > > > >I'm running into a problem with tomcat, which I believe is > >self-inflicted. > > Mostly I just want to confirm my suspicions. > > > >I'm doing some fairly high-rate polling (using > >JavaScript/XmlHttpRequest/DWR). I'm polling, which is just calling the > >DWR > >servlet once every second (using setTimeout on the response callback). > > > >Now.. So far nothing should seem out of the ordinary. And indeed many > >of > >these polling cycles do run and complete successfully. However after a > >number of cycles (somewhere around 60), I start to get > >NullPointerExceptions from the apache tomcat code. Looks like from the > >Response.recycle method, etc. Full stack trace below. > > > >Now.. I don't think there's anything wrong with tomcat here.. I've been > >using tomcat for years, and it's pretty rock solid. I suspect the > >problem > >is in my lack of understanding of the life cycle of the > >request/response > >objects. Here's the details in what I'm doing, and what I suspect I'm > >doing wrong: > > > >This poll has the job of batching up "data requests" from the client > >JavaScript code and passing them off to the server. On the server, > >each > >data request is spawned off to a new thread using a thread pool. After > >the > >threads are posted to the thread pool, the originating servlet request > >returns. However, before the response is committed, when the thread is > >created for the thread pool, I'm assigning the HttpServletRequest and > >Response (and the HttpSession) as local thread variables. Once the > >thread > >is finished, I remove the references by assigning the local variables > >to > >null. > > > >So.. When I'm trying to preserve the request, response and session > >objects > >in a thread, knowing that the response will be committed before the > >thread > >dies, am I breaking a cardinal rule? > > Yes. > > > Should I expect that tomcat will > >throw NullPointerExceptions because of this? > > Yes. > > However, there is some good news. If you use the async API, the app can > stay pretty much as is. > > The short version is: > - use startAsync and pass the async context to your threads > - have those threads write to the response (make sure you don't write > concurrently) > - call complete once all the threads have completed > > Mark > > > > > >Full stack trace:Aug 30, 2013 9:50:51 PM > >org.apache.coyote.http11.Http11Processor process > >SEVERE: Error finishing response > >java.lang.NullPointerException > >at > >org.apache.tomcat.util.http.MimeHeaders.setValue(MimeHeaders.java:302) > >at > > >org.apache.coyote.http11.Http11Processor.prepareResponse(Http11Processor.java:1558) > >at > >org.apache.coyote.http11.Http11Processor.action(Http11Processor.java:958) > >at org.apache.coyote.Response.action(Response.java:181) > >at > > >org.apache.coyote.http11.InternalOutputBuffer.endRequest(InternalOutputBuffer.java:403) > >at > >org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:903) > >at > > >org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) > >at > >org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) > >at java.lang.Thread.run(Thread.java:680) > >Aug 30, 2013 9:50:51 PM > >org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler process > >SEVERE: Error reading request, ignored > >java.lang.NullPointerException > >at org.apache.tomcat.util.http.MimeHeaders.clear(MimeHeaders.java:152) > >at org.apache.coyote.Response.recycle(Response.java:579) > >at > > >org.apache.coyote.http11.InternalOutputBuffer.nextRequest(InternalOutputBuffer.java:373) > >at > >org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:925) > >at > > >org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606) > >at > >org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) > >at java.lang.Thread.run(Thread.java:680) > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > >