We use exchange server for getting email and open connection for 30 minutes and then automatically reopen it for next 30 minutes. But when we want to deploy new war-file and stops tomcat service, connection doesn't close while connection period doesn't end (30 minutes). So tomcat service cannot be started for this interval. I tried to handle server stopping with shutdown hook like this
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable(){
public void run() {
connection.close();
}
}));
but it doesn't work. Is there some another way to close connection?
Connection to exchange server is in new thread. Tomcat 7.
Also we want to handle (close connection) stopping tomcat in any way.
P.S. Sorry for my English.
Update: I found that destroy method of bean executes, but connection closes in 1-2 minutes. It's still too long for websites.