Hello,

We have an app that uses a ScheduledExecutorService to delay some interactions 
with another web service. The basic use case here is that a user logs in, 
performs some action that results in a Runnable being sent to the 
ScheduledExecutorService with a delay so that it’s executed later, and then the 
user logs out. This all works fine, except where it doesn’t.

One place where it doesn’t work fine is if we want to update the running app 
and terminate an instance—any app instance might be holding Runnables that are 
scheduled to execute later, and yet have no active sessions and would thus be 
candidates for a shutdown via “refuse new sessions”. Until now, we’ve been 
keeping track of the scheduled Runnables somewhat indirectly (the details don’t 
matter), and it’s been reasonably successful. However, it occurred to me that I 
might be able to use gracefulTerminate() to wait until there are no more 
outstanding Runnables in the queue. In development, this works just fine: using 
a while loop we check for outstanding scheduled Runnables and then sleep for 5 
seconds. When there are none, we call super.gracefulTerminate() and the app 
shuts down.

My questions:

1. I assume that setting "refuse new sessions” on an instance in JavaMonitor 
will eventually send a SIGTERM to the app which will be caught by the graceful 
shutdown mechanism. (Hitting the stop button in Eclipse, for example, doesn’t 
do that and so gracefulTerminate() isn’t called. You have to simulate it by 
sending SIGTERM to the Java process from a terminal.) That is, will this even 
work in production? (I can’t imagine the answer here is no, but would be good 
to know if anyone’s doing/done it.)

2. The Javadocs for gracefulTerminate() talk about "last minute cleanup”, but I 
assume we can wait an arbitrary amount of time here. We could conceivably have 
delays of _hours_ on some of the Runnables in the queue—is this going to bother 
JavaMonitor (or anything else)? (I assume JavaMonitor will continue to honour 
“refuse new sessions”, for example.)

Obviously we will test this out, but if someone is doing anything like this, it 
would be great to hear about it. Finally, yes, there are probably much better 
ways to achieve the outcome here (database-backed Quartz Scheduler, for 
example), but this was the solution that fit into the budget constraints.


-- 
Paul Hoadley
http://logicsquad.net/




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to