commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Wang <>
Subject RE: Commons daemon - stop the service
Date Thu, 31 May 2012 17:53:05 GMT
Thanks for the comments.
I set both start mode and stop mode to JVM. My test showed that worked best for me. The procrun
documentation says that to use this mode, the start method should not stop until stop is called.
My start method exits immediately but it did not seem to be the cause of my grievances. My
stop code also calls System.exit() in a separate thread, after couple of seconds of sleep.
I cannot get rid of it because some of our customers still want to start and stop the application
using batch scripts. But the stop did not fail consistently with "unexpected" stoppage. That
makes me think that there is an issue of timing. 
What I have recently tried is to terminate most, if not all, threads spawned by the applications
gracefully. That seemed to have improved the performance (fewer error messages from service
manager). But my testing is done when the app is not loaded with much work. What will happen
when a thread needs 20 more minutes to complete its job? Would procrun be patient enough to
wait (if I set the timeout to 20 minutes)? It is hard to test this scenario because I have
not been able to put a heavy load on the application. So I would like know what actually happens
after procrun calls the stop class? Does it monitor the JVM in some way? Does procrun eventually
call System.exit() to shut down JVM?

James Wang

-----Original Message-----
From: Mladen Turk [] 
Sent: Thursday, May 31, 2012 12:15 PM
Subject: Re: Commons daemon - stop the service

On 05/31/2012 02:37 PM, James Wang wrote:
> I need some insights on how procrun shuts down an application. Procrun 
> has a parameter called "StopTimeout" which Defines the timeout in seconds that procrun
waits for service to exit gracefully. What happens after the timeout period? Doe procrun shut
down the JVM?
> A more general question is: how do the involved parties interact with 
> one another - JVM, procrun, and Windows service manager? I have been perplexed by two
errors: one says the process ended unexpectedly. The other says service manager could not
get a response from procrun (after a long wait). In both cases, the event viewer showed errors
related to prunsrv.exe. These errors are more associated with the 32 bit version. AMD64 seems
to work a better.

Depends on the mode you select.
In general service stop is treated as separate process which should by some IPC mechanism
inform the 'service' to stop.

The simplest one is System.exit, which just calls System.exit() for the service.
More complex involves either special process or method call which must cause main service
to exit cleanly.

Shutdown timeout can occur if any of those goes over defined timeout.
Service code should never call System.exit by itself cause that can lead to 'process ended
Reason is because 'stop' waits for 'start' to finish and then 'stopped'
is reported to service manager.

So if your service code uses system.exit then you must use java mode which spawns a separate
process and stop is then program which must by some IPC (usually socket) inform the 'master'
to shut down.

With jvm mode all that happens in the same process (and the same JVM) thus your stop code
must set some variable in main program which will cause clean exit from main method. This
can be tricky if you depend on daemon threads.

Hope that shares some light.


To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message