package com.*.data.busisystem.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.*.data.busisystem.Lock;
@RestController
public class LockController {
// 10 秒中,可以访问10次
@GetMapping("/test")
@Lock
public String lock() {
// RedisAtomicInteger entityIdCounter = new RedisAtomicInteger("entityIdCounter", redisTemplate.getConnectionFactory());
// String date = DateFormatUtils.format(new Date(), "yyyy-MM-dd H:mm:ss.SSS");
try {
System.out.println("加锁后,休眠前");
Thread.sleep(10000);
System.out.println("加锁后,休眠后");
} catch (InterruptedException e) {
e.printStackTrace();
}
return "测试代码";
}
}
本文介绍了如何使用Spring Boot的@Controller和@Lock注解实现一个10秒内的限流功能,通过Lock控制并发访问,核心展示了获取锁后休眠10秒的操作。
1028

被折叠的 条评论
为什么被折叠?



