Creating Spring Framework task programmatically?
You just need to wrap your target object in a Runnable
, and submit that:
private Target target; // this is a Spring bean of some kind@Autowired private TaskScheduler taskScheduler;public void scheduleSomething() { Runnable task = new Runnable() { public void run() { target.doTheWork(); } }; taskScheduler.scheduleWithFixedDelay(task, delay);}