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

去掉多余的toString,+ 拼接LocalTime.now()已自动转字符串
This commit is contained in:
cxh 2024-11-19 09:55:18 +08:00
parent 2e47ddf634
commit d84a0ecfac

View File

@ -1,5 +1,6 @@
package org.dromara.demo.controller; package org.dromara.demo.controller;
import cn.hutool.core.thread.ThreadUtil;
import com.baomidou.lock.LockInfo; import com.baomidou.lock.LockInfo;
import com.baomidou.lock.LockTemplate; import com.baomidou.lock.LockTemplate;
import com.baomidou.lock.annotation.Lock4j; import com.baomidou.lock.annotation.Lock4j;
@ -33,13 +34,9 @@ public class RedisLockController {
@Lock4j(keys = {"#key"}) @Lock4j(keys = {"#key"})
@GetMapping("/testLock4j") @GetMapping("/testLock4j")
public R<String> testLock4j(String key, String value) { public R<String> testLock4j(String key, String value) {
System.out.println("start:" + key + ",time:" + LocalTime.now().toString()); System.out.println("start:" + key + ",time:" + LocalTime.now());
try { ThreadUtil.sleep(10000);
Thread.sleep(10000); System.out.println("end :" + key + ",time:" + LocalTime.now());
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("end :" + key + ",time:" + LocalTime.now().toString());
return R.ok("操作成功", value); return R.ok("操作成功", value);
} }
@ -54,11 +51,7 @@ public class RedisLockController {
} }
// 获取锁成功处理业务 // 获取锁成功处理业务
try { try {
try { ThreadUtil.sleep(8000);
Thread.sleep(8000);
} catch (InterruptedException e) {
//
}
System.out.println("执行简单方法1 , 当前线程:" + Thread.currentThread().getName()); System.out.println("执行简单方法1 , 当前线程:" + Thread.currentThread().getName());
} finally { } finally {
//释放锁 //释放锁