You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
reader/app/src/main/java/com/novel/read/utlis/MyTimeTask.java

35 lines
734 B

package com.novel.read.utlis;
import java.util.Timer;
import java.util.TimerTask;
/**
* create by zlj on 2019/7/15
* describe:
*/
public class MyTimeTask {
private Timer timer;
private TimerTask task;
private long time;
public MyTimeTask(long time, TimerTask task) {
this.task = task;
this.time = time;
if (timer == null){
timer=new Timer();
}
}
public void start(){
timer.schedule(task, 0, time);//每隔time时间段就执行一次
}
public void stop(){
if (timer != null) {
timer.cancel();
if (task != null) {
task.cancel(); //将原任务从队列中移除
}
}
}
}