许鹏程
2024-01-15 1be3406d2c07ec7c1376044f77a3bbd2576bf256
product-server-data-center/src/main/java/com/product/data/center/utils/CustomLock.java
@@ -6,7 +6,9 @@
import com.product.core.spring.context.SpringMVCContextHolder;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
 * @Author cheng
@@ -16,7 +18,7 @@
public class CustomLock {
    private Set<String> obj = new ConcurrentHashSet<>();
   private Map<String, Long> obj = new ConcurrentHashMap<>();
    private long detectionWaitTime = 1000L;
@@ -43,7 +45,7 @@
        if (!StringUtils.isEmpty(key)) {
            key = key.toUpperCase();
            synchronized (key.intern()) {
                if (!this.obj.contains(key)) {
            if (!this.obj.containsKey(key)) {
                    lock(key);
                    return true;
                }
@@ -66,7 +68,7 @@
//        boolean enterLock = false;
        long starTime = System.currentTimeMillis();
        Long outLogTime = null;
        while (this.obj.contains(obj)) {
      while (this.obj.containsKey(obj)) {
            if (System.currentTimeMillis() - starTime >= (1000 * 60 * 5)) {
                if (outLogTime == null || System.currentTimeMillis() - outLogTime >= (1000 * 60)) {
                    outLogTime = System.currentTimeMillis();
@@ -81,7 +83,7 @@
//            SpringMVCContextHolder.getSystemLogger().info("等待定时间:" + (System.currentTimeMillis() - starTime) + " ms,lockKey:" + obj);
//        }
//        SpringMVCContextHolder.getSystemLogger().info("上锁成功,lockKey:" + obj);
        this.obj.add(obj);
      this.obj.put(obj, System.currentTimeMillis());
    }
    public void unLock(String... key) {