From 1be3406d2c07ec7c1376044f77a3bbd2576bf256 Mon Sep 17 00:00:00 2001
From: 许鹏程 <1821349743@qq.com>
Date: 星期一, 15 一月 2024 10:25:50 +0800
Subject: [PATCH] commit
---
product-server-data-center/src/main/java/com/product/data/center/utils/CustomLock.java | 122 ++++++++++++++++++++--------------------
product-server-data-center/src/main/java/com/product/data/center/service/CommonService.java | 5 +
2 files changed, 67 insertions(+), 60 deletions(-)
diff --git a/product-server-data-center/src/main/java/com/product/data/center/service/CommonService.java b/product-server-data-center/src/main/java/com/product/data/center/service/CommonService.java
index 58e94e0..46071e5 100644
--- a/product-server-data-center/src/main/java/com/product/data/center/service/CommonService.java
+++ b/product-server-data-center/src/main/java/com/product/data/center/service/CommonService.java
@@ -48,6 +48,11 @@
@Value("${data.system.name}")
private String dataSystemName;
+ public void deleteCenterLog() {
+ this.getBaseDao().executeUpdate("DELETE FROM product_sys_data_center_log WHERE uuid in (select * from product_sys_data_center_log_del_v) limit 10000");
+ }
+
+
/**
* 鍒涘缓瀹氭椂浠诲姟
*
diff --git a/product-server-data-center/src/main/java/com/product/data/center/utils/CustomLock.java b/product-server-data-center/src/main/java/com/product/data/center/utils/CustomLock.java
index b1f1981..331802b 100644
--- a/product-server-data-center/src/main/java/com/product/data/center/utils/CustomLock.java
+++ b/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,87 +18,87 @@
public class CustomLock {
- private Set<String> obj = new ConcurrentHashSet<>();
+ private Map<String, Long> obj = new ConcurrentHashMap<>();
- private long detectionWaitTime = 1000L;
+ private long detectionWaitTime = 1000L;
- /**
- * 鏃犲弬鏋勯�犳椂
- */
- public CustomLock() {
- }
+ /**
+ * 鏃犲弬鏋勯�犳椂
+ */
+ public CustomLock() {
+ }
- /**
- * @param detectionWaitTime 妫�娴嬬瓑寰呮椂闂达紝鍗曚綅姣
- */
- public CustomLock(long detectionWaitTime) {
- this.detectionWaitTime = detectionWaitTime;
- }
+ /**
+ * @param detectionWaitTime 妫�娴嬬瓑寰呮椂闂达紝鍗曚綅姣
+ */
+ public CustomLock(long detectionWaitTime) {
+ this.detectionWaitTime = detectionWaitTime;
+ }
- public boolean tryLock(String[] key) {
- return this.tryLock(ArrayUtil.join(key, ","));
- }
+ public boolean tryLock(String[] key) {
+ return this.tryLock(ArrayUtil.join(key, ","));
+ }
- public boolean tryLock(String key) {
- if (!StringUtils.isEmpty(key)) {
- key = key.toUpperCase();
- synchronized (key.intern()) {
- if (!this.obj.contains(key)) {
- lock(key);
- return true;
- }
- }
- }
- return false;
- }
+ public boolean tryLock(String key) {
+ if (!StringUtils.isEmpty(key)) {
+ key = key.toUpperCase();
+ synchronized (key.intern()) {
+ if (!this.obj.containsKey(key)) {
+ lock(key);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
- public void lock(String... key) {
- this.lock(ArrayUtil.join(key, ","));
- }
+ public void lock(String... key) {
+ this.lock(ArrayUtil.join(key, ","));
+ }
- public void lock(String key) {
- String obj = key;
- if (StringUtils.isEmpty(obj)) {
- return;
- }
- obj = obj.toUpperCase();
+ public void lock(String key) {
+ String obj = key;
+ if (StringUtils.isEmpty(obj)) {
+ return;
+ }
+ obj = obj.toUpperCase();
// boolean enterLock = false;
- long starTime = System.currentTimeMillis();
- Long outLogTime = null;
- while (this.obj.contains(obj)) {
- if (System.currentTimeMillis() - starTime >= (1000 * 60 * 5)) {
- if (outLogTime == null || System.currentTimeMillis() - outLogTime >= (1000 * 60)) {
- outLogTime = System.currentTimeMillis();
- SpringMVCContextHolder.getSystemLogger().error("绛夊緟閲婃斁閿佹椂闂磋秴杩�5鍒嗛挓,绛夊緟鏃堕棿锛�" + (System.currentTimeMillis() - starTime) + "ms,lockKey:" + obj);
- }
- }
+ long starTime = System.currentTimeMillis();
+ Long outLogTime = null;
+ while (this.obj.containsKey(obj)) {
+ if (System.currentTimeMillis() - starTime >= (1000 * 60 * 5)) {
+ if (outLogTime == null || System.currentTimeMillis() - outLogTime >= (1000 * 60)) {
+ outLogTime = System.currentTimeMillis();
+ SpringMVCContextHolder.getSystemLogger().error("绛夊緟閲婃斁閿佹椂闂磋秴杩�5鍒嗛挓,绛夊緟鏃堕棿锛�" + (System.currentTimeMillis() - starTime) + "ms,lockKey:" + obj);
+ }
+ }
// enterLock = true;
// SpringMVCContextHolder.getSystemLogger().info("閿侀噴鏀剧瓑寰�,lockKey:" + obj);
- ThreadUtil.sleep(this.detectionWaitTime);
- }
+ ThreadUtil.sleep(this.detectionWaitTime);
+ }
// if (enterLock) {
// 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) {
- String obj = ArrayUtil.join(key, ",");
- unLock(obj);
- }
+ public void unLock(String... key) {
+ String obj = ArrayUtil.join(key, ",");
+ unLock(obj);
+ }
- public void unLock(String key) {
+ public void unLock(String key) {
- if (StringUtils.isEmpty(key)) {
- return;
- }
- this.obj.remove(key.toUpperCase());
+ if (StringUtils.isEmpty(key)) {
+ return;
+ }
+ this.obj.remove(key.toUpperCase());
// SpringMVCContextHolder.getSystemLogger().info("閲婃斁閿佹垚鍔�,lockKey:" + key);
- }
+ }
}
--
Gitblit v1.9.2