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

com.noir.common.lock.ReentrantDLock Maven / Gradle / Ivy

There is a newer version: 0.1.6-RELEASE
Show newest version
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