fix: LocalConstant 改用 ConcurrentHashMap 保证线程安全,LzTool 方法名拼写修正

- LocalConstant: HashMap → ConcurrentHashMap,put() 改用 putIfAbsent 消除 check-then-act 竞态
- LzTool: 私有方法 setDateAndComplate → setDateAndComplete(拼写修正,仅内部调用)
This commit is contained in:
yukaidi
2026-05-29 03:14:10 +08:00
parent aa30571709
commit 07a330cfd4
2 changed files with 6 additions and 7 deletions

View File

@@ -1,7 +1,7 @@
package cn.qaiu.vx.core.util; package cn.qaiu.vx.core.util;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* vertx 上下文外的本地容器 为不在vertx线程的方法传递数据 * vertx 上下文外的本地容器 为不在vertx线程的方法传递数据
@@ -10,11 +10,10 @@ import java.util.Map;
* @author <a href="https://qaiu.top">QAIU</a> * @author <a href="https://qaiu.top">QAIU</a>
*/ */
public class LocalConstant { public class LocalConstant {
private static final Map<String, Object> LOCAL_CONST = new HashMap<>(); private static final Map<String, Object> LOCAL_CONST = new ConcurrentHashMap<>();
public static Map<String, Object> put(String k, Object v) { public static Map<String, Object> put(String k, Object v) {
if (LOCAL_CONST.containsKey(k)) return LOCAL_CONST; LOCAL_CONST.putIfAbsent(k, v);
LOCAL_CONST.put(k, v);
return LOCAL_CONST; return LOCAL_CONST;
} }

View File

@@ -290,12 +290,12 @@ public class LzTool extends PanBase {
if (location0 == null) { if (location0 == null) {
fail(downUrl + " -> 直链获取失败2, 可能分享已失效"); fail(downUrl + " -> 直链获取失败2, 可能分享已失效");
} else { } else {
setDateAndComplate(location0); setDateAndComplete(location0);
} }
}).onFailure(handleFail(downUrl)); }).onFailure(handleFail(downUrl));
return; return;
} }
setDateAndComplate(location); setDateAndComplete(location);
}) })
.onFailure(handleFail(downUrl)); .onFailure(handleFail(downUrl));
} catch (Exception e) { } catch (Exception e) {
@@ -304,7 +304,7 @@ public class LzTool extends PanBase {
}).onFailure(handleFail(url)); }).onFailure(handleFail(url));
} }
private void setDateAndComplate(String location0) { private void setDateAndComplete(String location0) {
// 分享时间 提取url中的时间戳格式lanzoui.com/abc/abc/yyyy/mm/dd/ // 分享时间 提取url中的时间戳格式lanzoui.com/abc/abc/yyyy/mm/dd/
String regex = "(\\d{4}/\\d{1,2}/\\d{1,2})"; String regex = "(\\d{4}/\\d{1,2}/\\d{1,2})";
Matcher matcher = Pattern.compile(regex).matcher(location0); Matcher matcher = Pattern.compile(regex).matcher(location0);