Reputation: 175
I am in the need of changing the executing time of a runnig task for a ScheduledThreadPoolExecutor.
i have something like
executor.schedule(new Runnable() {blablal},10,TimeUnit.SECONDS);
during the login phase, i would like to pick up all the tasks for this user and execute them once.
it's not possible to change the execution time of the ScheduledFuture right?
so my best option it's to do something like
synchronized(list) {
Runnable a = new Runnable(){aaaa; list.remove(a)};
executor.schedule(a,10,TimeUnit.SECONDS);
list.add(a);
}
and at login
synchronize(list) {
for (Runnable a : list)
a.run();
}
am i right?
there aren't any other better options, so i can avoid all this synchronization?
maybe a direct way to change the timeout of a ScheduledFuture
Upvotes: 1
Views: 632
Reputation: 106
Keep a handle on the Future
that is returned when you schedule something on the ScheduledExecutor. Instead of trying to change the execution time, you can cancel the future and re-schedule it.
Upvotes: 3