All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jobrunr.utils.resilience.Lock Maven / Gradle / Ivy

Go to download

An easy way to perform background processing on the JVM. Backed by persistent storage. Open and free for commercial use.

There is a newer version: 7.3.1
Show newest version
package org.jobrunr.utils.resilience;

import java.util.concurrent.Semaphore;

public class Lock implements AutoCloseable {

    private final Semaphore semaphore;

    public Lock() {
        this.semaphore = new Semaphore(1);
    }

    public Lock lock() {
        semaphore.acquireUninterruptibly();
        return this;
    }

    public boolean isLocked() {
        return this.semaphore.availablePermits() < 1;
    }

    public void close() {
        unlock();
    }

    public void unlock() {
        semaphore.release();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy