Reputation: 419
I am trying to extend AbstractScheduledService.Scheduler
so that I can use a schedule that stores initial delay and period in instance variable.
I am trying with the following
public class ScannerScheduler extends AbstractScheduledService.Scheduler {
@Override
public final Future<?> schedule(AbstractService as,
ScheduledExecutorService ses, Runnable task) {
Executors.newSingleThreadScheduledExecutor()
.scheduleAtFixedRate(task, 0, 1, TimeUnit.DAYS);
}
}
But the compiler still complains with:
ScannerScheduler is not abstract and does not override abstract method schedule(AbstractService,ScheduledExecutorService,Runnable) in Scheduler
What am I missing?
Upvotes: 0
Views: 1257
Reputation: 718886
REVISED
The Scheduler
class has a private
constructor, which means that you cannot extend it without modifying the Guava library code.
You therefore need to take the alternative approach suggested by the javadocs.
If more flexibility is needed then consider subclassing
CustomScheduler
.
(The compilation error is a bit misleading in this case ... but the bottom line is that the extend
approach will not work.)
Upvotes: 4
Reputation: 12205
The method Future<?> schedule(AbstractService service, ScheduledExecutorService executor,
Runnable runnable)
of AbstractScheduledService
is final, and thus cannot be overridden.
From the code there, it seems that the same method signature in the class Scheduler
can be overridden, don't know if that helps you though:
new Scheduler() {
@Override
public Future<?> schedule(AbstractService service, ScheduledExecutorService executor,
Runnable task) {
return executor.scheduleWithFixedDelay(task, initialDelay, delay, unit);
}
};
Upvotes: 0