Java Thread every X seconds

后端 未结 4 1658
旧巷少年郎
旧巷少年郎 2020-12-07 22:45

What is the easiest way to have a piece of Java code scheduled at a given rate ?

4条回答
  •  既然无缘
    2020-12-07 23:19

    By using a ScheduledExecutorService.

    Have a look at Executors.newScheduledThreadPool. It will allow you to created a ScheduledExecutorService which lets you submit Runnables to be executed at regular intervals.

提交回复
热议问题