com.noir.common.lock.ReentrantDLock Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-boot-distributed-lock-starter Show documentation
Show all versions of spring-boot-distributed-lock-starter Show documentation
A distributed lock springboot supports
package com.noir.common.lock;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.locks.Lock;
public abstract class ReentrantDLock implements Lock {
private ThreadLocal> localLocks = new ThreadLocal<>();
protected boolean isEntered(String lockName) {
List locks = localLocks.get();
if (Objects.isNull(locks)) {
return false;
}
return locks.contains(lockName);
}
protected void enter(String lockName) {
List locks = localLocks.get();
if (Objects.isNull(locks)) {
localLocks.set(new ArrayList<>());
locks = localLocks.get();
}
locks.add(lockName);
}
protected void exit(String lockName) {
List locks = localLocks.get();
locks.remove(lockName);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy