简体   繁体   中英

Java EE @Schedule and server down

I have the following task in Java EE 8, running on WildFly.

public class MyScheduler {

    @Schedules({
            @Schedule(dayOfWeek = "Fri", hour = "17")
    })
    public void performCronTask() {
        System.out.println("MyScheduler started.");
    }
}

This will run every Friday at 17 (5PM). What happens if the server goes down at 16 and restarts at 18? Will the server run the task or not? Do I need to control this situation programmatically?

Yes it will be execututed. According to EJB 3.1 the @Schedule annotation contains attribute which defines if the scheduler is persistent or not. By default the scheduler is persistent. Here is an article going in details on how to configure programmatic and annotation based scheduler https://www.baeldung.com/scheduling-in-java-enterprise-edition

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM