7

I use spring boot and somewhere in code I have following code:

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

Is there way to replace it via programmatic style?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

11

You seem to be able to do it without Spring Annotations like said in the documentation: 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));
Michael
  • 41,989
  • 11
  • 82
  • 128
CharlieNoodles
  • 316
  • 2
  • 9