读书人

JAVA中用Timer做定时更新数据,怎么取消

发布时间: 2012-01-31 21:28:41 作者: rapoo

JAVA中用Timer做定时更新数据,如何取消这个线程
急!!第一次使用Timer,可以实现定时更新,但是我的页面关闭后,这个线程还是在跑着,我需要在推出的按钮中加个监听来取消这个线程,应该怎么写方法呢?我还想做个刷新功能,怎么判断Timer起的线程是否存在呢?代码如下:(其中CacheStorageSystem 类继承了TimerTask)注:我是在其他页面做的按钮监听
public class UpdateAll {

private final Timer timer = new Timer();

private static Composite composite;

public void execute(){

CacheStorageSystem cache = new CacheStorageSystem();
Date date = new Date();
long timestamp = 30000;

timer.schedule(cache, date, timestamp);

}
}

[解决办法]
我记得Timer有个cancle方法可以取消来着

读书人网 >Java相关

热点推荐