1. addShutdownHook
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run()
{
try {
// TODO
关闭服务时回收资源
} catch (Exception e)
{
logger.error(e.getMessage(),
e);
}
try
{
super.finalize();
}
catch (Throwable e)
{
StartUp.logger.error("super.finalize() error
when stop server",
e);
}
}
});
2.
原文:http://www.cnblogs.com/RoyalRaul/p/3638130.html