{"record":{"id":"d949e808c3b44268","repo":"binarywang/WxJava","slug":"acquire-timeouted","errorCode":null,"errorMessage":"acquire timeouted","messagePattern":"acquire timeouted","errorType":"exception","errorClass":"WxRuntimeException","httpStatus":null,"severity":"error","filePath":"weixin-java-common/src/main/java/me/chanjar/weixin/common/util/locks/JedisDistributedLock.java","lineNumber":32,"sourceCode":" * @deprecated 不建议使用jedis-lock这个过期组件，不可靠\n *\n * @author <a href=\"https://github.com/007gzs\">007</a>\n */\n@Deprecated\npublic class JedisDistributedLock implements Lock {\n  private final Pool<Jedis> jedisPool;\n  private final JedisLock lock;\n\n  public JedisDistributedLock(Pool<Jedis> jedisPool, String key){\n    this.jedisPool = jedisPool;\n    this.lock = new JedisLock(key);\n  }\n\n  @Override\n  public void lock() {\n    try (Jedis jedis = jedisPool.getResource()) {\n      if (!lock.acquire(jedis)) {\n        throw new WxRuntimeException(\"acquire timeouted\");\n      }\n    } catch (InterruptedException e) {\n      throw new WxRuntimeException(\"lock failed\", e);\n    }\n  }\n\n  @Override\n  public void lockInterruptibly() throws InterruptedException {\n    try (Jedis jedis = jedisPool.getResource()) {\n      if (!lock.acquire(jedis)) {\n        throw new WxRuntimeException(\"acquire timeouted\");\n      }\n    }\n  }\n\n  @Override\n  public boolean tryLock() {\n    try (Jedis jedis = jedisPool.getResource()) {","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/locks/JedisDistributedLock.java#L14-L50","documentation":"Thrown by JedisDistributedLock.lock() when lock.acquire(jedis) returns false, meaning the Redis-based JedisLock could not obtain the lock within its acquire timeout. It is a WxRuntimeException signalling contention: another holder kept the lock past the wait window.","triggerScenarios":"Multiple JVMs/threads contending on the same lock key while the holder exceeds the acquire timeout; Redis heavily loaded so acquire retried out; lock key never released due to a crash and the lease did not expire yet.","commonSituations":"Cross-node token refresh serialized on a shared lock with too-short acquire timeout; a previous holder died without releasing and the lease TTL is long; Redis cluster failover mid-acquire.","solutions":["Tune the JedisLock acquire timeout/lease to match expected hold time.","Ensure holders always release in a finally block and keep critical sections short.","Scale the Redis pool and check Redis latency/health.","Consider a non-blocking tryLock() path with a fallback instead of blocking lock()."],"exampleFix":"// before\ndistributedLock.lock();\n// after\nif (!distributedLock.tryLock(waitMs, TimeUnit.MILLISECONDS)) {\n  throw new ServiceBusyException(\"try again later\");\n}","handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  distributedLock.lock();\n} catch (WxRuntimeException e) {\n  if (\"acquire timeouted\".equals(e.getMessage())) {\n    // contention - back off or fail fast\n  }\n  throw e;\n}","preventionTips":["Use tryLock with a bounded timeout for contended paths.","Keep critical sections short and always release in finally.","Tune acquire timeout/lease to match expected hold time."],"tags":["redis","jedis","distributed-lock","concurrency"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}