Repeat a task with a time delay?

后端 未结 12 1565
小蘑菇
小蘑菇 2020-11-22 02:14

I have a variable in my code say it is \"status\".

I want to display some text in the application depending on this variable value. This has to be done with a speci

12条回答
  •  春和景丽
    2020-11-22 02:35

    I think the new hotness is to use a ScheduledThreadPoolExecutor. Like so:

    private final ScheduledThreadPoolExecutor executor_ = 
            new ScheduledThreadPoolExecutor(1);
    this.executor_.scheduleWithFixedDelay(new Runnable() {
    @Override
    public void run() {
        update();
        }
    }, 0L, kPeriod, kTimeUnit);
    

提交回复
热议问题