I am trying to execute a periodic action using Java Concurrency package and I am using the following code:
ScheduledExecutorService daemon = Executors.newScheduledThreadPool(1);
daemon.scheduleWithFixedDelay(new AddressThread(ParentMap.getSingletonInstance(), dictionary, test),10, 10, TimeUnit.SECONDS);
where AddressThread
is a Runnable
type that is passed. The code executes run()
every 10 seconds and it is working as I expect. However, I need to return a value and run()
does not let me do that. Is there a similar method like scheduleWithFixedDelay where I can pass a Callable
interface rather than a Runnable
and return something back? If not, how can I do equivalent stuff like above if I want to return a value?