Bob Smith wrote:
> Hi,
>
> I have migrated a TCP based server to a servlet and cannot figure out how to
> get multi-threading working.
>
> The TCP server works like this;
>
> Listen for Request:
> read command code from the accepted socket;
> find a free thread containing a slave server who can handle the command;
> hand the socket over to the freeserver and interrupt the thread
> (the slave server reads and writes to the handed-over socket)
> Listen for next request
>
> What happens when I put this into a servlet is this;
> doPost is invoked
> find a free thread containing a slave server who can handle the command;
> get inputstream (from request) and outputstream (from response) and
> hand these streamsover to a free server thread and interrupt the thread
> doPost finishes
>
> I think what happens next is that Tomcat completes the request cycle,
> including
> closing the socket( and associated request/response stream) thereby screwing
> over the slave thread still process the command code.
>
> I want Tomcat to leave these streams alone and be ready to invoke the
> servlet
> for the next request. Is there support for this kind of stuff in Tomcat?
>
> Thanks
> -Bob
> [...]
Hi :-) I am not sure, I think:
- it is Servlet container who do the same work with your ServerSocket
in your TCP server, i.e., container will listen to the request, find/make
a pooled-free/new thread, and let it work with that instance of your
Servlet class.
- then in service/doGet/doPut in your Servlet class, you can do the similar
work with what you did in that pooled-free/new thread in TCP server.
Bo
may.14, 2001