You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Tam, Michael" <mt...@pfc.cfs.nrcan.gc.ca> on 2003/03/27 01:26:33 UTC

Help: start and shutdown a process through servlet

Hi all,

I am having a problem to use a servlet to invoke an external process and I
wish someone can give me some suggests on my approach which may help me
solve the issue.

Environment:
Windows, J2SDK 1.4.1_02, and Tomcat 4.1.24.


The scenario:

1) I would like to dedicate a servlet to invoke an external process i.e.
init() -> start the process and destroy() -> ends the process.
2) My process is a small and simple server process which use datagramsocket
to listen to localhost:port and handle messages which come from a client
servlet.
3) Currently, in the init() I initiate a static Runtime and get a static
reference of the process which is created by the runtime.exec("java
server",null,"path to the server class").  In the destroy(), I use send a
datagram message to the server which causes the shutdown of the server and I
call the process.waitfor() to wait until the server process completed before
destroy() exits.


problem:

1)  tomcat startups fine and the servlet has invoked the server process.
However, when I use a standalone client to talk to the server process, only
the first send/receive is completed.  The client doesn't receive any thing
corresponded to the second message and is infinitely waiting the response
from the server process.

2) After 1), attempt to shutdown tomcat and tomcat is not responding.
Forcing tomcat to shutdown by closing the prompt, then the server process
starts to work again and execute the 'queued' message.


Any input would be deeply appreciated.

Regards,
Michael

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org