From 0a0e20ae08a2318e3297fe3d035180d225ffd09c Mon Sep 17 00:00:00 2001 From: "1049970895@qniao.cn" <1049970895> Date: Tue, 6 Sep 2022 16:44:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E7=B4=A2=E5=BC=95=E6=97=B6?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=85=AC=E5=B9=B3=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/device/power/IotDevicePowerOnAndOffDataJob.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/iot-device-power-on-and-off-data-job/src/main/java/com/qniao/iot/device/power/IotDevicePowerOnAndOffDataJob.java b/iot-device-power-on-and-off-data-job/src/main/java/com/qniao/iot/device/power/IotDevicePowerOnAndOffDataJob.java index fd4c6c7..a8a6c00 100644 --- a/iot-device-power-on-and-off-data-job/src/main/java/com/qniao/iot/device/power/IotDevicePowerOnAndOffDataJob.java +++ b/iot-device-power-on-and-off-data-job/src/main/java/com/qniao/iot/device/power/IotDevicePowerOnAndOffDataJob.java @@ -58,6 +58,7 @@ import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.locks.ReentrantLock; @Slf4j public class IotDevicePowerOnAndOffDataJob { @@ -82,6 +83,8 @@ public class IotDevicePowerOnAndOffDataJob { return requestConfigBuilder; })); + private static final ReentrantLock lock = new ReentrantLock(true); + /** * 当前索引日期后缀 */ @@ -328,6 +331,7 @@ public class IotDevicePowerOnAndOffDataJob { GetIndexRequest exist = new GetIndexRequest(indicesName); // 先判断客户端是否存在 try { + lock.lock(); boolean exists = restHighLevelClient.indices().exists(exist, RequestOptions.DEFAULT); if (!exists) { // 创建索引 @@ -387,6 +391,8 @@ public class IotDevicePowerOnAndOffDataJob { } } catch (Exception e) { e.printStackTrace(); + }finally { + lock.unlock(); } } }