定时运行程序

 Runnable runnable = new Runnable() {
public void run() {
task to run goes here
try {
body();//需要运行的函数名
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
//e.printStackTrace();
}
}
};//设定一个线程
ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor();
// System.out.println("kaishi检测。。。。");
// 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间
service.scheduleAtFixedRate(runnable, 0, 7, TimeUnit.DAYS);//启动定时扫描
原文地址:https://www.cnblogs.com/ermei/p/5832242.html