Correct/Optimized way to reschedule a Java task in a ScheduledExecutorService?

Suppose that we have a Java Task (eg: Runnable ) that will be executed if we do not receive an external signal in x seconds.

A common way to solve this problem is to use a schedule thread pool (such as ScheduledExecutorService ) to execute this task considering x delay. When we receive that external event, from other part of the system, we need to reschedule this task, that is, to reinsert this task in the thread pool with x delay.

My question is: what is the correct/optimized way to reschedule a task in a ScheduleExecutorService ? Current solutions usually focus on removing/canceling and reinserting the dealyed task in the thread pool. Is this the best approach?

链接地址: http://www.djcxy.com/p/83130.html

上一篇: Facebook SDK:发布到墙上仅供我进行测试用途?

下一篇: 正确/优化的方式重新安排ScheduledExecutorService中的Java任务?