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

org.rx.core.Locker Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package org.rx.core;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.rx.bean.WeakIdentityMap;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Locker {
    public static final Locker INSTANCE = new Locker();
    //key1: ref, key2: key
    final Map> holder = new WeakIdentityMap<>();

    public ReentrantLock getLock(Object ref, Object key) {
        return holder.computeIfAbsent(ref, k -> new ConcurrentHashMap<>())
                .computeIfAbsent(key, k -> new ReentrantLock());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy