Planning task using java spring mvc

I need to schedule a task to run automatically in java. I need the same window scheduling functionality. I did this daily, every year, but got stuck when I came to the weekly schedule. Not getting how to do it. I am using java calendar. Please help find one good solution.

Any help or ideas will be visible.

+4
source share
1 answer

Scheduling a task in Spring can be done in 4 ways, as shown below.

1. Scheduling tasks using the fixed delay attribute in the annotation @Scheduled.

public class DemoServiceBasicUsageFixedDelay {
    @Scheduled(fixedDelay = 5000)
    // @Scheduled(fixedRate = 5000)
    public void demoServiceMethod() {
        System.out.println("Method executed at every 5 seconds. Current time is :: " + new Date());
    }
}

2. cron @Scheduled

@Scheduled(cron = "*/5 * * * * ?")
public void demoServiceMethod() {
    System.out.println("Method executed at every 5 seconds. Current time is :: " + new Date());
}

3. cron .

@Scheduled(cron = "${cron.expression}")
public void demoServiceMethod() {
    System.out.println("Method executed at every 5 seconds. Current time is :: " + new Date());
}

4. cron,

public class DemoServiceXmlConfig {
    public void demoServiceMethod() {
        System.out.println("Method executed at every 5 seconds. Current time is :: " + new Date());
    }
}

XML # 4

<task:scheduled-tasks>
        <task:scheduled ref="demoServiceXmlConfig" method="demoServiceMethod" cron="#{applicationProps['cron.expression']}"></task:scheduled>
</task:scheduled-tasks>

http://howtodoinjava.com/2013/04/23/4-ways-to-schedule-tasks-in-spring-3-scheduled-example/

, .

+6

All Articles