使用Java的API可以指定周期地启动线程。
设置从现在开始(从0秒开始),每隔10秒,启动一个线程
ScheduledExecutorService ses = Executors.newScheduledThreadPool(1);
ses.scheduleAtFixedRate(new PeroidSchedualRunnable(), 0, 10, TimeUnit.SECONDS);
运行的线程为
package com.nicchagil.fsl;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
public class PeroidSchedualRunnable implements Runnable {
public static int count = 0;
public void run() {
// Used to simulate the cost of business
try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("PeroidSchedualRunnable run " + count++ + " at " + new SimpleDateFormat("yyyy-