gstackoverflow
gstackoverflow

Reputation: 37034

How to replace @SchedulerLock with programmatic style

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?

Upvotes: 10

Views: 10891

Answers (1)

CharlieNoodles
CharlieNoodles

Reputation: 356

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));

Upvotes: 15

Related Questions