Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing scheduled tasks in Spring

I have a couple of tasks scheduled within Spring's task scheduler:

<task:scheduled-tasks>
    <task:scheduled ref="task1" method="run"
        cron="0 0 */0 * * *" />
    <task:scheduled ref="task2" method="run"
        cron="0 0 */30 * * *" />
</task:scheduled-tasks>

<task:scheduler id="scheduler" pool-size="10" />

How can I access a list of scheduled tasks and retrieve meta-information (e.g the next execution time) from within the application context?

ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
ThreadPoolTaskScheduler scheduler = (ThreadPoolTaskScheduler)context.getBean("scheduler");
//... how to continue from here?
like image 672
achingfingers Avatar asked Jul 29 '14 14:07

achingfingers


People also ask

How do I access Scheduled Tasks?

To open Scheduled Tasks, click Start, click All Programs, point to Accessories, point to System Tools, and then click Scheduled Tasks. Use the Search option to search for "Schedule" and choose "Schedule Task" to open the Task Scheduler. Select the "Task Scheduler Library" to see a list of your Scheduled Tasks.

What is @scheduled annotation in Spring?

The @EnableScheduling annotation is used to enable the scheduler for your application. This annotation should be added into the main Spring Boot application class file. @SpringBootApplication @EnableScheduling public class DemoApplication { public static void main(String[] args) { SpringApplication.

What is Spring taskScheduler?

Spring task scheduler is either configured with @scheduled annotation or dynamically with Java code, to schedule a task. @EnableScheduling is required to enable support for Spring task scheduling. Spring task scheduling can be a challenge in clustered environments, where multiple instances of the same application run.


1 Answers

There is no public API in Spring to do this.

Related:

  • How are Spring <task:scheduled> objects represented at runtime?
like image 105
Sotirios Delimanolis Avatar answered Sep 18 '22 22:09

Sotirios Delimanolis