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.