/**
* 服务器启动关闭的监听器
* @version 1.0
*/
public
class
GlobalListener
implements
ServletContextListener {
private
static
final
Logger log = LoggerFactory.getLogger(GlobalListener.
class
);
private
Timer timer =
new
Timer();
/**
* 关闭服务器
*/
public
void
contextDestroyed(ServletContextEvent event) {
log.info(
"关闭服务器"
);
timer.cancel();
}
/**
* 启动服务器
*/
public
void
contextInitialized(ServletContextEvent event) {
ApplicationContext ctx =
WebApplicationContextUtils.
getWebApplicationContext(event.getServletContext());
ctx.getBean("dao");
log.info(
"启动服务器"
);
FrameConfig.waterImgPath =
"/common_res/images/water.jpg"
;
FrameConfig.maxCacheSize =
10000
;
FrameConfig.encoding =
"UTF-8"
;
timer.schedule(
new
TaskTimer(), getMillisecond(), Task.daySeconds * 1000l);
// 每天执行一次
}
// 从现在到明天最早时间相差的毫秒数
private
Long getMillisecond() {
DateUtil util = DateUtil.getBean();
String beginTime = util.getDetachDate(util.getNowDate(
0
) +
" 00:00:00"
,
2
, Task.daySeconds.intValue());
return
util.getDateDiff(util.getNowDate(
1
), beginTime) * 1000l;
}
}
web.xml
<listener>
<listener-
class
>com.xxx.GlobalListener</listener-
class
>
</listener>