You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Heinemann, Andreas" <An...@Dresdner-Bank.com> on 2000/12/05 10:41:40 UTC

doPost() and concurrency issue


Hi,

i've got a question/problem concerning the doPost() method.

As far as I know, whenever there is a new request, tomcat creates
a new thread running through the doPost() method. Inside this
method, my code does nothing special. But is passes the request and
response objects to a queue. this queue is managed by other threads.
then doPost() finishes. 

My question is: What happens to the request response objects when 
                doPost() ends?

It  looks to me, that tomcat does some kind of cleanup, especially 
doing something with the stream objects attached to the 
request/response objects.

I've outlined some code in the 'first scenario' and got unexpected
behavior. Seldom there occurs no error. Most of the time a client, who
is reading the response, gets an java.io.StreamCorruptedError. 
Sometimes  it is an java.io.EOFException.

In the 'second scenario', I block the doPost()-thread, therefore making
sure,
that the request and response objects are still there and  valid.
Now there is no such problem.

Any ideas?

thanks, andreas

ps: i'm using tomcat 3.1 and java 1.3 under winNT


first scenario:
---------------

public void doPost(HttpServletRequest request,
                   HttpServletResponse response)
                   throws ServletException, IOException {
         .
         .
     // pass request and response object to a
     // queue. this queue will be managed by
     // another thread. eventually this other thread
     // will take the response object, call
     // response.getOutputStream()
     // and write to the client using this stream.
         .
         .
         .
     // leave doPost()
}



second scenario:
----------------

public void doPost(HttpServletRequest request,
                   HttpServletResponse response)
                   throws ServletException, IOException {
         .
         .
     // pass request and response object to a
     // queue. this queue will be managed by
     // another thread. eventually this other thread
     // will take the response object, call
     // response.getOutputStream()
     // and write to the client using this stream.
         .
         .
     // block the  thread and wait for the 'queue' thread to
     // write a response via response.getOutputStream()
         .
         .
     // leave doPost()
}