可以用线程来做,每隔几秒开一个线程
代码如下
public void runTask() {
final long timeInterval = 120000;// 两分钟运行一次
final ThreadService threadService = new ThreadService();
Runnable runnable = new Runnable() {
public void run() {
while (true) {
// ------- code for task to run
//你要运行的程序
// ------- ends here
try {
Thread.sleep(timeInterval);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
Thread thread = new Thread(runnable);
thread.start();
}