refactor ThreadUtil.sleep代替Thread.sleep,减少太try catch
This commit is contained in:
parent
8d595cf1c4
commit
2e47ddf634
@ -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, 停止接收新任务并尝试完成所有已存在任务.
|
||||
|
@ -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));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user