user17982723
user17982723

Reputation:

how to create scheduler which triggers a job at every 13 hours in java

how to create scheduler which triggers a job at every 13 hours in java for example if it starts at

Upvotes: 1

Views: 632

Answers (2)

Aleksandar Grujic
Aleksandar Grujic

Reputation: 93

In Spring Boot, you can just annotate a method with the @Scheduled annotation and the main class with the @EnableScheduling.

Examples:

Main class in Spring application

@EnableScheduling 
@SpringBootApplication
public class ScheduledDemoApplication {

  public static void main(String[] args) {
    SpringApplication.run(ScheduledDemoApplication.class, args);
  }
}

and create a method in a separate class that will be triggered on a schedule:

@Scheduled(some cron exp here)
public void execute() {
  // some logic that will be executed on a schedule
}

This should work fine.

Here is a good article on how to schedule a Spring Boot task.

Upvotes: 1

bilak
bilak

Reputation: 4922

what about using @Scheduled(cron="0 0 */13 * * * ")

EDIT: you can check here the only difference is that spring has added the first place (first *) for seconds.

EDIT2: you can actually use also fixedRate @Scheduled(fixedRate="13", timeunit=TimeUnit.HOURS)

Upvotes: 2

Related Questions