Q:

Detect when the serves is about to sleep on CloudBees

I wrote a REST server application using Jersey, and I deployed on CloudBees.  Since I have a free account the server will go to sleep after 2 hours of inactivity.  Before this happens I would like to save data on a database; how could I detect the sleep event on the cloudbees server?  Thanks for your answers! 

A:

Getting application to hibernate is a standard servlet container shutdown, so a ServletContextListener can handle this.  Another option is for you to have a periodic Timer task to store data on DB, as application may also just crash for various reason, and you'd them have data lost 

