refactor ThreadUtil.sleep代替Thread.sleep,减少太try catch

This commit is contained in:
cxh 2024-11-19 09:54:19 +08:00
parent 8d595cf1c4
commit 2e47ddf634
2 changed files with 2 additions and 17 deletions

View File

@ -14,18 +14,6 @@ import java.util.concurrent.*;
@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class Threads {
/**
* sleep等待,单位为毫秒
*/
public static void sleep(long milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (InterruptedException e) {
return;
}
}
/**
* 停止线程池
* 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务.

View File

@ -1,5 +1,6 @@
package org.dromara.demo.controller;
import cn.hutool.core.thread.ThreadUtil;
import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.domain.R;
import org.dromara.common.redis.utils.RedisUtils;
@ -83,11 +84,7 @@ public class RedisCacheController {
RedisUtils.setCacheObject(key, value);
boolean flag = RedisUtils.expire(key, Duration.ofSeconds(10));
System.out.println("***********" + flag);
try {
Thread.sleep(11 * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ThreadUtil.sleep(11 * 1000);
Object obj = RedisUtils.getCacheObject(key);
return R.ok(value.equals(obj));
}