public class PlatContextListener implements ServletContextListener{
??? private Timer timer = null;
??? /** 應用程序的根目錄 */
??? private static String contextPath = null;
???
??? /** Creates a new instance of PlatContextListener */
??? public PlatContextListener() {
??? }
??? public void contextInitialized(ServletContextEvent sce) {
??????? ServletContext sc = sce.getServletContext();
??????? contextPath = sc.getRealPath("").replace("\\", "/");
???????
??????? int nInterval=24*60*60*1000;
???????
??????? timer = new Timer(true);
???????
??????? //每天零晨3點執行清理工作
??????? Calendar calendar = Calendar.getInstance();
??????? calendar.set(Calendar.HOUR_OF_DAY,3);
??????? calendar.set(Calendar.MINUTE,0);
??????? calendar.set(Calendar.SECOND,0);
??????? Date time = calendar.getTime();
???
??????? timer.scheduleAtFixedRate(new PlatTimerClearTask(), time,nInterval);
???????
??? }
??? public void contextDestroyed(ServletContextEvent sce) {
??????? timer.cancel();
??? }
???
??? public static String getContextPath() {
??????? return contextPath;
??? }
???
}
大盤預測
國富論
posted on 2007-10-11 14:50
華夢行 閱讀(162)
評論(0) 編輯 收藏 所屬分類:
JDK