How can I use the Java concurrency API to get a reference to the task that is scheduled for execution?
I can do something like this, and keep the reference to myRunnable:
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
SimpleRunnable myRunnable = new SimpleRunnable();
exec.scheduleAtFixedRate(myRunnable, 0, 2, TimeUnit.SECONDS);
But is there a way to use the Executor service or ScheduledFuture
to get the reference?
This question shows a collection of Future
objects and discusses that they keep a reference to the task, but I don't see any public API method exposing it.