Accessing scheduled tasks in Spring Accessing scheduled tasks in Spring spring spring

Accessing scheduled tasks in Spring


I just figured this out

start with this to get whats scheduled.

    ThreadPoolTaskScheduler xScheduler = (ThreadPoolTaskScheduler)this.taskScheduler;    ScheduledThreadPoolExecutor xService = (ScheduledThreadPoolExecutor)xScheduler.getScheduledExecutor();    BlockingQueue<Runnable> queue = xService.getQueue();    Object[] scheduledJobs = queue.toArray();

If this array look at instance in debugger to find what you need out.

Then write reflection code like this to get at the hidden API's in Spring and Java. See the set Accessible this is only way to get at these private items. You might need to use different public classes to get at certain private fields, look at api docs and view source on these classes in eclipse.

            Method delayM = obj.getClass().getDeclaredMethod("getDelay", TimeUnit.class);            delayM.setAccessible(true);            // delayM = obj.getClass().getDeclaredMethod("getDelay", TimeUnit.class);            Long delay = (Long)delayM.invoke(obj, new Object[] { tu } );

The trigger and root runnable is in the callable field of this object , instance of ReschedulingRunnable which is not a public class, ask Spring why they did this. You can get the delegate out of DelegatingErrorHandlingRunnable with reflection.