https://github.com/edgar-code-repository/spring-boot-scheduled-process
Spring Boot app that shows how to schedule tasks using @Scheduled annotation.
https://github.com/edgar-code-repository/spring-boot-scheduled-process
Last synced: 8 months ago
JSON representation
Spring Boot app that shows how to schedule tasks using @Scheduled annotation.
- Host: GitHub
- URL: https://github.com/edgar-code-repository/spring-boot-scheduled-process
- Owner: edgar-code-repository
- Created: 2021-02-28T02:13:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-24T22:48:13.000Z (about 5 years ago)
- Last Synced: 2025-01-23T04:29:28.967Z (over 1 year ago)
- Language: Java
- Homepage:
- Size: 57.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
SCHEDULED PROCESS
------------------------------------------------------------------------------
Spring Boot app that shows how to schedule tasks using @Scheduled annotation.
Built with Java 11, Spring Boot 2, Gradle and Lombok.
------------------------------------------------------------------------------
The class ScheduledExample uses the annotation @EnableScheduling and contains
a method that uses the annotation @Scheduled.
This method runs every 5 seconds, taking this value from the properties file.
```
package com.example.demo.configuration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import lombok.extern.java.Log;
@Component
@Log
@EnableScheduling
public class ScheduledExample {
private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
@Scheduled(fixedRateString = "${invoiceProcess.fixedRate}", initialDelay = 1000)
public void processing() {
log.info("[ScheduledExample][processing][START]");
log.info("[ScheduledExample][processing][LocalDateTime.now(): " + dateTimeFormatter.format(LocalDateTime.now()) + "]");
log.info("[ScheduledExample][processing][END]");
}
}
```
------------------------------------------------------------------------------