⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 定时器.txt

📁 计时器服务依赖于加载 Timer 类的主机的系统日期。如果侦听器主机具有不同的系统日期
💻 TXT
字号:
xml中
<?xml version="1.0" encoding="UTF-8" ?> 
  <!DOCTYPE web-app (View Source for full doctype...)> 
- <web-app>
  <display-name>struts</display-name> 
- <filter>
  <filter-name>encodingFilter</filter-name> 
  <filter-class>cn.spoto.ZhEncoderFilter</filter-class> 
- <init-param>
  <param-name>encode</param-name> 
  <param-value>GBK</param-value> 
  </init-param>
  </filter>
- <filter-mapping>
  <filter-name>encodingFilter</filter-name> 
  <servlet-name>action</servlet-name> 
  </filter-mapping>
- <filter-mapping>
  <filter-name>encodingFilter</filter-name> 
  <url-pattern>*.jsp</url-pattern> 
  </filter-mapping>
- <listener>
  <listener-class>cn.spoto.TopicListener</listener-class> 
  </listener>
- <servlet>
  <servlet-name>action</servlet-name> 
  <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> 
- <init-param>
  <param-name>config</param-name> 
  <param-value>/WEB-INF/struts-config.xml</param-value> 
  </init-param>
- <init-param>
  <param-name>debug</param-name> 
  <param-value>3</param-value> 
  </init-param>
- <init-param>
  <param-name>detail</param-name> 
  <param-value>3</param-value> 
  </init-param>
  <load-on-startup>0</load-on-startup> 
  </servlet>
- <servlet-mapping>
  <servlet-name>action</servlet-name> 
  <url-pattern>*.do</url-pattern> 
  </servlet-mapping>
- <welcome-file-list>
  <welcome-file>index.jsp</welcome-file> 
  </welcome-file-list>
- <taglib>
  <taglib-uri>bean.tld</taglib-uri> 
  <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> 
  </taglib>
- <taglib>
  <taglib-uri>html.tld</taglib-uri> 
  <taglib-location>/WEB-INF/struts-html.tld</taglib-location> 
  </taglib>
- <taglib>
  <taglib-uri>logic.tld</taglib-uri> 
  <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> 
  </taglib>
- <taglib>
  <taglib-uri>nested.tld</taglib-uri> 
  <taglib-location>/WEB-INF/struts-nested.tld</taglib-location> 
  </taglib>
- <taglib>
  <taglib-uri>template.tld</taglib-uri> 
  <taglib-location>/WEB-INF/struts-template.tld</taglib-location> 
  </taglib>
- <taglib>
  <taglib-uri>tiles.tld</taglib-uri> 
  <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location> 
  </taglib>
  </web-app>


package cn.spoto;

import hibernate.TopicOperate;

import java.util.TimerTask;

import javax.servlet.ServletContext;

public class MyTimerTask extends TimerTask {

	 private ServletContext servletContext = null; 
	 TopicOperate to = new TopicOperate();
	
	public MyTimerTask(ServletContext servletContext) {
		this.servletContext=servletContext;
	}

	@Override
	public void run() {
		servletContext.setAttribute("topics2", to.queryAll2());

	}

}


package cn.spoto;

import java.util.List;
import java.util.Timer;

import hibernate.TopicOperate;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class TopicListener implements ServletContextListener{

	Timer timer = new Timer(true);

	public void contextInitialized(ServletContextEvent arg0) {
		
		
		
		timer.schedule(new MyTimerTask(arg0.getServletContext()),0,5000);
		


	}
public void contextDestroyed(ServletContextEvent arg0) {
		
		timer.cancel(); 
		
		
	}

}

package cn.spoto;

import java.util.Timer;

//import hibernate.TopicOperate;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class TopicListener implements ServletContextListener{

	Timer timer = new Timer(true);

	public void contextInitialized(ServletContextEvent event) {
		
		
		
		//timer.schedule(new MyTimerTask(event.getServletContext()),0,5000);
		//timer.schedule(new MyTimer(event.getServletContext()),0,5000);
		timer.schedule(new MyTimer2(event.getServletContext()),0,60000);

	}
public void contextDestroyed(ServletContextEvent arg0) {
		
		timer.cancel(); 
		
		
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -