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>

Configuring

The quarkus.shedlock.defaults-lock-at-most-for application property is mandatory.

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: QUARKUS_SHEDLOCK_DEFAULTS_LOCK_AT_MOST_FOR

string

required

value which is much longer than normal execution time

Environment variable: QUARKUS_SHEDLOCK_DEFAULTS_LOCK_AT_LEAST_FOR

string

src/main/resources/application.properties
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
    }
}