Steve: Developing on the Edge - Making java server apps suspend/resume aware
Steve: Developing on the Edge
Thoughts on development, Web-services, technology and mountains.
20Jan
Wed2010
Making java server apps suspend/resume aware

I'm looking for an easy way for a server-side Java app to recognise that it has just resumed, and should handle that event (wait for the network to return, reconnect to things).

I don't see any easy way to do this, other than have a shell script to run on power resume which somehow notifies the app (touches a file, probably; queues something). The java app has to look for this file and react (polling, bad), or when it encounters network problems look at this file and say "did we just resume? Maybe the lan isn't live".

Life would be simpler if java apps could subscribe to power/LAN events

Comments

On 20 January 2010 at 15: 17 Odi commented:
Depends how much non-runtime you consider "suspended". For an application there is (should be) no difference between suspend, SIGSTOP or not getting scheduled.
But suppose you set two timers A and B with expiry times B = A + 10 minutes. The 10 minutes is what you consider "suspended" here. On resume, these two timers will fire immediately and concurrently. While during normal operation they would fire sequentially. You could detect that difference easily.
It's quite a hackish approach though. But at least platform independent.
On 27 January 2010 at 08: 38 Steve Loughran commented:
That might work.
What SmartFrog does now is every child process on a single machine keeps track of the time it last got pinged by its parent. If the parent can't ping the child: liveness failure, rollback. If the child doesn't get pinged by the parent: assume parent is unreachable and rollback.
but what I could is say "if the gap between pings is suddenly a few minutes then we've been suspended and resumed, so try and do a short resync before overreacting"