Listener、Filter、Servlet与Java Web项目初始化的工作(3)
来源:未知 责任编辑:责任编辑 发表时间:2014-02-18 03:25 点击:次
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class TimerTest {
private static int i = 0;
public static void initTimer(Long seconds) {
TimerTest.schedule(new TimerTask() {
public void run() {
callUsers();
}
}, 0, seconds*1000);
}
public static void callUsers() {
System.out.println("Filter refreshed: " + ++i + " times.");
}
public static void schedule(TimerTask task, long delay, long period) {
Executors.newScheduledThreadPool(1).scheduleAtFixedRate(task, delay, period,
TimeUnit.MILLISECONDS);
}
}
class TimerTest01 extends TimerTask {
private static int i = 0;
@Override
public void run() {
System.out.println("Servlet refreshed: " + ++i + " times.");
}
}
class TimerTest02 extends TimerTask {
private static int i = 0;
@Override
public void run() {
System.out.println("Listener refreshed: " + ++i + " times.");
}
}
[html]
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>HelloFilter</filter-name>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>