标签:
/**
* 服务器启动关闭的监听器
* @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) {
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>
标签:
原文地址:http://www.cnblogs.com/leo3689/p/5009775.html