修改es多节点启动

This commit is contained in:
sh
2026-03-27 18:03:25 +08:00
parent 3426b7a101
commit 45ae067883

View File

@@ -96,9 +96,10 @@ public class ESJobSearchImpl implements IESJobSearchService
private boolean acquireDistributedLock() throws InterruptedException { private boolean acquireDistributedLock() throws InterruptedException {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < WAIT_LOCK_SECONDS * 1000) { while (System.currentTimeMillis() - start < WAIT_LOCK_SECONDS * 1000) {
boolean lockExists = redisCache.hasKey(ES_INIT_LOCK_KEY); Boolean success = redisCache.setIfAbsent(ES_INIT_LOCK_KEY,"es_init_locked",
if (!lockExists) { LOCK_EXPIRE_SECONDS,TimeUnit.SECONDS
redisCache.setCacheObject(ES_INIT_LOCK_KEY, "es_init_locked", LOCK_EXPIRE_SECONDS, TimeUnit.SECONDS); );
if (Boolean.TRUE.equals(success)) {
logger.info("成功获取ES初始化分布式锁key{}", ES_INIT_LOCK_KEY); logger.info("成功获取ES初始化分布式锁key{}", ES_INIT_LOCK_KEY);
return true; return true;
} }