是否有任何本地库或第三方支持,如ScheduledExecutorServicego lang 的 java native library 用于生产用例?
请在 java 1.8 中找到代码片段:
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class TaskScheduler {
/**
* @param args
*/
public static void main(String[] args) {
Runnable runnable = ()-> {
// task to run goes here
System.out.println("Hello !!");
};
ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
service.scheduleAtFixedRate(runnable, 0, 1, TimeUnit.SECONDS);
}
}
它将Hello !!每隔一秒打印一次。
汪汪一只猫
相关分类