2007-04-03
Weblogic下的自动任务
package com.jamesby.listener;
import java.util.*;
import javax.management.*;
import javax.naming.Context;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weblogic.management.timer.Timer;
public class AutoTaskManager implements HttpSessionListener,
HttpSessionAttributeListener, NotificationListener,
ServletContextListener {
private static final Log logger = LogFactory.getLog(AutoTaskManager.class);
private int count;
private ServletContext context = null;
public static final long PERIOD = Timer.ONE_DAY;
private long period;
private boolean debug;
private Timer timer;
private Integer notificationId;
public void contextInitialized(ServletContextEvent event) {
try {
initParams(event);
timer = new Timer();
timer.addNotificationListener(this, null, "Message Broker ");
Calendar cal = Calendar.getInstance();
Date timerTriggerAt = cal.getTime();
notificationId = timer.addNotification("Timer Type",
"Timer Message", this, timerTriggerAt, period);
timer.start();
} catch (Exception e) {
}
}
public void initParams(ServletContextEvent event) {
ServletContext ctx = event.getServletContext();
try {
period = PERIOD;
} catch (Exception e) {
period = Timer.ONE_DAY;
e.printStackTrace();
}
}
public void contextDestroyed(ServletContextEvent event) {
try {
timer.stop();
timer.removeNotification(notificationId);
} catch (InstanceNotFoundException e) {
e.printStackTrace();
}
}
public void handleNotification(Notification notif, Object handback) {
}
public void attributeAdded(HttpSessionBindingEvent se) {
}
public void attributeRemoved(HttpSessionBindingEvent se) {
}
public void attributeReplaced(HttpSessionBindingEvent se) {
}
public void sessionCreated(HttpSessionEvent se) {
}
public void sessionDestroyed(HttpSessionEvent se) {
}
}
发表评论
- 浏览: 129507 次
- 性别:


- 详细资料
搜索本博客
最近加入圈子
最新评论
-
iBatis学习小结
感谢辛勤劳动,希望能贡献更好的东西 :
-- by xuguangyun -
为什么我的Spring的声明事 ...
不要自己抛异常,spring不知道那是什么异常,在catch中直接抛出原来的异常 ...
-- by sinoalex -
Spring AOP 学习小结
写得非常好! 关于 AOP 的几个基础概念,我感觉Spring 的参考文档上面 ...
-- by Hejrcc -
Spring AOP 部分Class的 ...
是的,通过UML的类图,从整体上面了解类之间的关系,是一种不错的方式,理清类之间 ...
-- by rainlife -
Spring AOP 部分Class的 ...
感谢共享
-- by wangzhongjie






评论排行榜