tomcat监控器和定时器Java认证考试
文章作者 100test 发表时间 2010:01:01 15:50:52
来源 100Test.Com百考试题网
package cn.yicha.timer.
import java.text.SimpleDateFormat.
import java.util.Calendar.
import java.util.Date.
import java.util.Timer.
import javax.servlet.ServletContextEvent.
import javax.servlet.ServletContextListener.
import org.apache.log4j.Logger.
import cn.yicha.ask.AskBaidu.AskBaidu_Inti.
import cn.yicha.common.*.
//import jp.yicha.video.action.IndexAction.
public class MainTimerListener implements ServletContextListener {
//public static final Logger logger = Logger.getLogger(MainTimerListener.class.getName()).
private static Logger logger = Logger.getLogger(MainTimerListener.class).
private Timer timer = null.
public void contextInitialized(ServletContextEvent event) {
try{
// 在这里初始化监听器,在tomcat启动的时候监听器启动,可以在这里实现定时器功能
Const.load().
int startHour = Integer.parseInt(Const.TimerStart).
int periodHour = Integer.parseInt(Const.TimerPeriod).
//renyy add method
AskBaidu_Inti.askinit().
//renyy add method
Calendar c = Calendar.getInstance().
c.add(Calendar.DATE,1).
c.set(Calendar.HOUR_OF_DAY,startHour).
c.set(Calendar.MINUTE,0).
c.set(Calendar.SECOND,0).
c.set(Calendar.MILLISECOND,0).
Date start = c.getTime().
// long delay = start.getTime() - System.currentTimeMillis().//tomcat启动后间隔1000毫秒启动
long period = periodHour * 60 * 60 * 1000. //间隔
//long period =