Skip to content

Commit cf772f6

Browse files
committed
refactor: RedisLock 定时续期线程池大小设置 cpu 核数
1 parent c8b5634 commit cf772f6

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • common/plugin/cache/src/main/java/top/cadecode/uniboot/common/plugin/cache/util

common/plugin/cache/src/main/java/top/cadecode/uniboot/common/plugin/cache/util/RedisLockKit.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class RedisLockKit {
2828
private final Map<String, LockContent> contentMap = new ConcurrentHashMap<>();
2929

3030
// 定时续期任务线程池,合理设置大小
31-
private final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(10);
31+
private static final ScheduledThreadPoolExecutor RENEW_EXECUTOR = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors());
3232

3333
/**
3434
* 阻塞式的获取锁
@@ -209,7 +209,7 @@ private boolean tryLock0(String name, Object value) {
209209
*/
210210
private ScheduledFuture<?> renewLock(String name, Object value) {
211211
// 有效期设置为 30s,每 15 秒重置
212-
return executor.scheduleAtFixedRate(() -> {
212+
return RENEW_EXECUTOR.scheduleAtFixedRate(() -> {
213213
Boolean success = redisTemplate.opsForValue().setIfPresent(name, value, 30, TimeUnit.SECONDS);
214214
if (Objects.equals(success, true)) {
215215
return;

0 commit comments

Comments
 (0)