Porting code from using timers to scheduledexecutorservice

前端 未结 3 1335
终归单人心
终归单人心 2021-01-15 16:31

I am trying to port code from using java timers to using scheduledexecutorservice

I have the following use case

class A {

    public boolean execut         


        
3条回答
  •  攒了一身酷
    2021-01-15 17:20

    It looks ok. Depending on what you're doing, you may want to keep executor service around as a member so you can use it again. Also, you can get a ScheduledFuture back from the scheduleXX() methods. This is useful because you can call get() on it to pull any exceptions that occur in the timed thread back to your control thread for handling.

提交回复
热议问题