Created
June 1, 2021 06:21
-
-
Save A-pZ/84ff6948aac3d59d9afa5767547f785f to your computer and use it in GitHub Desktop.
SchedLock execution method sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.scheduling.annotation.Scheduled; | |
import org.springframework.stereotype.Service; | |
import com.github.apz.repository.TaskRepository; | |
import lombok.AllArgsConstructor; | |
import lombok.extern.slf4j.Slf4j; | |
import net.javacrumbs.shedlock.core.SchedulerLock; | |
@Service | |
@AllArgsConstructor | |
@Slf4j | |
public class TaskSchedulerService { | |
TaskRepository repository; | |
@Scheduled(cron = "0/10 * * * * ?", zone = "Asia/Tokyo") | |
@SchedulerLock(name = "TaskScheduler_scheduledTask") | |
public void registerNormal() { | |
log.info("****normal"); | |
repository.register("normal"); | |
} | |
@Scheduled(cron = "30 0/1 * * * ?", zone = "Asia/Tokyo") | |
@SchedulerLock(name = "TaskScheduler_scheduledTaskSlow", lockAtLeastForString = "PT2M", lockAtMostForString = "PT30S") | |
public void registerSlow() { | |
log.info("----slow"); | |
repository.register("slow"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment