1

Sorry for my somewhat confusion but i am getting a little confused and need some assistance with concurrency.

If i have a thread pool in a class which calculates some value every 10 seconds such as this

private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
executorService.schedule(callable, 10, TimeUnit.SECONDS);

How can I determine when the result has come back. When the result is ready I need to process a map and do some calculations and then delete / empty the map

The only way I can think of is to user Observable interface but I am guessing this is not the correct approach

Thanks

Biscuit128
  • 5,218
  • 22
  • 89
  • 149
  • 1
    Why don't you initiate the followup action from within the scheduled task? That would be the most natural approach. – Marko Topolnik Oct 07 '14 at 08:22
  • Have a look at the return type of `schedule()` method? – Braj Oct 07 '14 at 08:25
  • It returns a scheduled future < integer> however - this essentially won't run once, it will run continuously with the number changing, so do i just need to keep checking for scheduled future.isdone in a loop? once is done is true i have a new result? – Biscuit128 Oct 07 '14 at 08:27

1 Answers1

1

You can use ScheduledFuture and invoke isDone (because ScheduledFuture extends Future) like this

ScheduledFuture schedule = executorService.schedule(callable, 10, TimeUnit.SECONDS);
schedule.isDone()
sol4me
  • 15,233
  • 5
  • 34
  • 34