3

我使用spring boot,在代码中的某处我有以下代码:

@SchedulerLock(name = "onlineIngestionTask", lockAtMostFor = 900, lockAtLeastFor = 900)
    public void pullTasksFromRemote() throws InterruptedException {
        logger.info("task-started");
        Thread.sleep(500);
        logger.info("task-stopped");
    }

有没有办法通过编程风格替换它?

4

1 回答 1

7

您似乎可以在没有 Spring Annotations 的情况下做到这一点,如文档中所述:https ://github.com/lukas-krecan/ShedLock#running-without-spring

LockingTaskExecutor executor = new DefaultLockingTaskExecutor(lockProvider);

...

Instant lockAtMostUntil = Instant.now().plusSeconds(600);
executor.executeWithLock(runnable, new LockConfiguration("lockName", lockAtMostUntil));
于 2019-02-11T11:02:24.490 回答