📜  java 间隔运行代码 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:38.040000             🧑  作者: Mango

代码示例1
/* Perform this runnable code every 5 seconds  in this example*/
   Runnable runnable = new Runnable() {
            public void run() {
                // task to run goes here
                System.out.println("Hello !!");
            }
        };
        ScheduledExecutorService service = Executors
                .newSingleThreadScheduledExecutor();
        service.scheduleAtFixedRate(runnable, 0, 5, TimeUnit.SECONDS);