update - 测试分布式锁

This commit is contained in:
wangli 2024-07-02 09:41:00 +08:00
parent 439a2ceac5
commit 67865c8be0

View File

@ -1,6 +1,7 @@
package cn.axzo.workflow.core.engine.interceptor;
import cn.axzo.workflow.core.engine.cmd.AbstractCommand;
import liquibase.pro.packaged.T;
import org.flowable.common.engine.impl.interceptor.AbstractCommandInterceptor;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandConfig;
@ -58,7 +59,7 @@ public class CustomLockProcessInstanceInterceptor extends AbstractCommandInterce
} finally {
log.info("finally unlock threadName: {}, token: {}", Thread.currentThread().getName(), token);
if (token != null) {
unlock(abstractCommand.getProcessInstanceId(), token);
unlock(KEY_PREFIX + abstractCommand.getProcessInstanceId(), token);
}
}
}
@ -141,16 +142,22 @@ public class CustomLockProcessInstanceInterceptor extends AbstractCommandInterce
try {
Long result = (Long) conn.scriptingCommands().eval(unlockScript.getBytes(Charset.forName("UTF-8")),
ReturnType.INTEGER, 1, keysAndArgs);
if (result != null && result > 0)
if (result != null && result > 0) {
return true;
} else {
throw new IllegalStateException("unLock ProcessInstance fail");
}
} catch (Exception e) {
log.warn("unlock error: {}", e.getMessage(), e);
// unlock(name, token);
return false;
try {
Thread.sleep(1000L);
} catch (InterruptedException ex) {
// ignore
}
return unlock(name, token);
} finally {
RedisConnectionUtils.releaseConnection(conn, factory);
}
return false;
}