Shedlock In Memory Provider
Shedlock In Memory provider give the ability to apply local locks. Under the hood an HashMap is used to store the locks.
Installation
If you want to use this extension, you need to add the io.quarkiverse.shedlock:quarkus-shedlock-provider-inmemory extension first to your build file.
For instance, with Maven, add the following dependency to your POM file:
<dependency>
<groupId>io.quarkiverse.shedlock</groupId>
<artifactId>quarkus-shedlock-provider-inmemory</artifactId>
<version>0.0.3</version>
</dependency>
Extension Configuration Reference
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
|---|---|---|
how long the lock should be kept in case the executing node dies Environment variable: |
string |
required |
value which is much longer than normal execution time Environment variable: |
string |
quarkus.shedlock.defaults-lock-at-most-for=PT30S
How to use it
To activate the lock on a method just annotate it with @InMemorySchedulerLock.
import jakarta.enterprise.context.ApplicationScoped;
import io.quarkiverse.shedlock.providers.inmemory.runtime.InMemorySchedulerLock;
@ApplicationScoped
public class InMemorySchedulerLockService {
@InMemorySchedulerLock
public void runUsingLock() {
// do something
}
}
The lock duration can be defined on the annotation directly likes this way:
import jakarta.enterprise.context.ApplicationScoped;
import io.quarkiverse.shedlock.common.runtime.LockDuration;
import io.quarkiverse.shedlock.providers.inmemory.runtime.InMemorySchedulerLock;
@ApplicationScoped
public class InMemorySchedulerLockServiceOptions {
@InMemorySchedulerLock(lockDuration = @LockDuration(lockAtMostFor = "PT30S", lockAtLeastFor = "PT10S"))
public void runUsingLock() {
// TODO do something
}
}