SpringBoot 接口并发限制(Semaphore)
可以使用 JMeter 辅助测试 https://blog.csdn.net/weixin_45014379/article/details/124190381
@RestController
@RequestMapping({"/Test"})
public class test {
Logger logger = LoggerFactory.getLogger(this.getClass());
// 使用 Semaphore 并发限制3个 超过阻塞
private final Semaphore permit = new Semaphore(3, true);
@GetMapping(value = {"/download"})
public String download(HttpServletRequest request) {
String result = "";
try {
// 获取令牌
logger.info("锁住 {}", Thread.currentThread().getName());
permit.acquire();
logger.info("下载 {}", Thread.currentThread().getName());
Thread.sleep(5000);
result = "Success";
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
} finally {
// 释放令牌
permit.release();
logger.info("释放 {}", Thread.currentThread().getName());
}
}
}
[2022-11-29 14:33:05.042] [http-nio-6201-exec-1] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-1
[2022-11-29 14:33:05.042] [http-nio-6201-exec-1] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-1
[2022-11-29 14:33:05.097] [http-nio-6201-exec-4] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-4
[2022-11-29 14:33:05.097] [http-nio-6201-exec-4] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-4
[2022-11-29 14:33:05.156] [http-nio-6201-exec-3] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-3
[2022-11-29 14:33:05.156] [http-nio-6201-exec-3] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-3
[2022-11-29 14:33:05.204] [http-nio-6201-exec-5] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-5
[2022-11-29 14:33:05.205] [http-nio-6201-exec-5] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-5
[2022-11-29 14:33:05.241] [http-nio-6201-exec-2] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-2
[2022-11-29 14:33:05.241] [http-nio-6201-exec-2] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-2
[2022-11-29 14:33:05.291] [http-nio-6201-exec-6] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-6
[2022-11-29 14:33:05.292] [http-nio-6201-exec-6] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-6
[2022-11-29 14:33:05.341] [http-nio-6201-exec-7] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-7
[2022-11-29 14:33:05.341] [http-nio-6201-exec-7] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-7
[2022-11-29 14:33:05.396] [http-nio-6201-exec-8] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-8
[2022-11-29 14:33:05.396] [http-nio-6201-exec-8] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-8
[2022-11-29 14:33:05.442] [http-nio-6201-exec-9] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-9
[2022-11-29 14:33:05.442] [http-nio-6201-exec-9] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-9
[2022-11-29 14:33:05.492] [http-nio-6201-exec-10] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-10
[2022-11-29 14:33:05.492] [http-nio-6201-exec-10] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-10
[2022-11-29 14:33:05.542] [http-nio-6201-exec-11] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-11
[2022-11-29 14:33:05.592] [http-nio-6201-exec-13] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-13
[2022-11-29 14:33:05.642] [http-nio-6201-exec-12] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-12
[2022-11-29 14:33:05.691] [http-nio-6201-exec-14] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-14
[2022-11-29 14:33:05.742] [http-nio-6201-exec-16] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-16
[2022-11-29 14:33:05.792] [http-nio-6201-exec-15] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-15
[2022-11-29 14:33:05.842] [http-nio-6201-exec-17] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-17
[2022-11-29 14:33:05.892] [http-nio-6201-exec-18] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-18
[2022-11-29 14:33:05.942] [http-nio-6201-exec-19] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-19
[2022-11-29 14:33:05.992] [http-nio-6201-exec-20] [INFO ] com.vipsoft.controller.ReleaseController - 锁住 http-nio-6201-exec-20
[2022-11-29 14:33:08.045] [http-nio-6201-exec-1] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-1
[2022-11-29 14:33:08.045] [http-nio-6201-exec-11] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-11
[2022-11-29 14:33:08.105] [http-nio-6201-exec-4] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-4
[2022-11-29 14:33:08.105] [http-nio-6201-exec-13] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-13
[2022-11-29 14:33:08.165] [http-nio-6201-exec-3] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-3
[2022-11-29 14:33:08.165] [http-nio-6201-exec-12] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-12
[2022-11-29 14:33:08.210] [http-nio-6201-exec-5] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-5
[2022-11-29 14:33:08.210] [http-nio-6201-exec-14] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-14
[2022-11-29 14:33:08.256] [http-nio-6201-exec-2] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-2
[2022-11-29 14:33:08.256] [http-nio-6201-exec-16] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-16
[2022-11-29 14:33:08.302] [http-nio-6201-exec-6] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-6
[2022-11-29 14:33:08.302] [http-nio-6201-exec-15] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-15
[2022-11-29 14:33:08.347] [http-nio-6201-exec-7] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-7
[2022-11-29 14:33:08.347] [http-nio-6201-exec-17] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-17
[2022-11-29 14:33:08.408] [http-nio-6201-exec-8] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-8
[2022-11-29 14:33:08.408] [http-nio-6201-exec-18] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-18
[2022-11-29 14:33:08.454] [http-nio-6201-exec-19] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-19
[2022-11-29 14:33:08.454] [http-nio-6201-exec-9] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-9
[2022-11-29 14:33:08.498] [http-nio-6201-exec-10] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-10
[2022-11-29 14:33:08.498] [http-nio-6201-exec-20] [INFO ] com.vipsoft.controller.ReleaseController - 工作 http-nio-6201-exec-20
[2022-11-29 14:33:11.047] [http-nio-6201-exec-11] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-11
[2022-11-29 14:33:11.109] [http-nio-6201-exec-13] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-13
[2022-11-29 14:33:11.167] [http-nio-6201-exec-12] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-12
[2022-11-29 14:33:11.213] [http-nio-6201-exec-14] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-14
[2022-11-29 14:33:11.258] [http-nio-6201-exec-16] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-16
[2022-11-29 14:33:11.304] [http-nio-6201-exec-15] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-15
[2022-11-29 14:33:11.350] [http-nio-6201-exec-17] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-17
[2022-11-29 14:33:11.411] [http-nio-6201-exec-18] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-18
[2022-11-29 14:33:11.458] [http-nio-6201-exec-19] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-19
[2022-11-29 14:33:11.503] [http-nio-6201-exec-20] [INFO ] com.vipsoft.controller.ReleaseController - 释放 http-nio-6201-exec-20
Disconnected from the target VM, address: '127.0.0.1:7367', transport: 'socket'
Process finished with exit code -1
SpringBoot 接口并发限制(Semaphore)的更多相关文章
- SpringBoot接口服务处理Whitelabel Error Page(转)
To switch it off you can set server.error.whitelabel.enabled=false http://stackoverflow.com/question ...
- SoapUI 利用SoapUI进行简单的接口并发测试
利用SoapUI进行简单的接口并发测试 by:授客 QQ:1033553122 测试环境: SoapUI Pro 5.1.2 步骤如下 1. 把请求添加到测试套件 1.1. 途径1 1.新 ...
- 2、SpringBoot接口Http协议开发实战8节课(1-6)
1.SpringBoot2.xHTTP请求配置讲解 简介:SpringBoot2.xHTTP请求注解讲解和简化注解配置技巧 1.@RestController and @RequestMapping是 ...
- Springboot接口简单实现生成MySQL插入语句
Springboot接口简单实现调用接口生成MySQL插入语句 在实际测试中,有这样一个需求场景,比如:在性能压力测试中,可能需要我们事先插入数据库中一些相关联的数据. 我们在实际测试中,遇到问题,需 ...
- SpringBoot接口服务处理Whitelabel Error Page
转载请注明来源:http://blog.csdn.net/loongshawn/article/details/50915979 <SpringBoot接口服务处理Whitelabel Erro ...
- Jmeter实时监控+SpringBoot接口性能实战
性能测试 Jmeter实时监控+SpringBoot接口性能实战 自动化 SpringBoot Java Jmeter实时监控+SpringBoot接口性能实战 一.实验目的及实验环境 1.1.实验目 ...
- PHP接口并发测试的方法
PHP接口并发测试的方法 <pre> header('Content-type:text/html; Charset=utf-8'); $uri = "输入你的url" ...
- Apache JMeter 做接口并发测试
获知来源:查找如何使用Postman进行接口并发测试时,在StackOverflow上看到,说postman只能做串行测试,而且postman并不是被设计做这种测试的:而jmeter就是为了测试而开发 ...
- webbench接口并发测试
webbench接口并发测试 安装 安装工程中可能会出现确实Ctags的情况,可以进行命令安装: Ubuntu:apt install ctags Centos:yum install cta ...
- postman批量调用接口并发测试
本文出自:https://www.cnblogs.com/2186009311CFF/p/11425913.html 接口测试在开发中很容易遇到,下面是请教别人学会的并发测试,希望能帮到需要用到的你, ...
随机推荐
- OA、CRM、SCM、ERP之间的区别和联系是什么?
当然,各个系统之间要集成.集成之后的东西,不叫做ERP.做ERP的人说叫ERP,做PLM的人说叫PLM,卖OA的人更愿意叫OA.其实,那个集成之后的东西,啥也不叫. 英文名 中文名 百科释义 关注 ...
- 题解 CF916C
题目大意: 要求构造一张图,并让该图满足以下条件: 有 \(n\) 个点,\(m\) 条边. 每条边的边权范围是 \([1,10^9]\). 图中从 \(1\) 到 \(n\) 的最短路径长度是个质数 ...
- Educational Codeforces Round 105 (Rated for Div. 2) A-C题解
写在前边 链接:Educational Codeforces Round 105 (Rated for Div. 2) A. ABC String 链接:A题链接 题目大意: 给定一个有\(A.B.C ...
- UIPath初识和安装
即使没有人为你鼓掌,也要优雅的谢幕,感谢自己的认真付出. 一. UiPath组成 学习UiPath,我们一定先要了解Studio,Robot和Orchestrator这3个重要组成部分. UiPa ...
- C#中的类和继承
公众号「DotNet学习交流」,分享学习DotNet的点滴. 类继承 通过继承我们可以定义一个新类,新类纳入一个已经声明的类并进行扩展. 可以使用一个已经存在的类作为新类的基础.已存在的类称为基类(b ...
- 【让AI女友跟我表白】大白话说Python+Flask入门(四)Flask Sijax的使用
写在前面 先吐槽两句,搞个mysql安装配置弄了4个小时,怎么都是外网无法访问,我靠,我特么也是服了. 当然,后来我投降了,明天再说,学什么不是学,娘的,换个方向,状态依然在! Sijax是什么? 代 ...
- [ABC311G] One More Grid Task
Problem Statement There is an $N \times M$ grid, where the square at the $i$-th row from the top and ...
- Android WebView 缓存处理
加载html时,会在data/应用下生成database和cache两个文件夹:请求的url存在webviewcache.db下面,url的内容保存在webviewCache下面, Webview的两 ...
- 若依vue启动报Error: error:0308010C:digital envelope routines::unsupported
解决:若依vue启动报Error: error:0308010C:digital envelope routines::unsupported 1.描述: 问题产生原因是因为 node.js V17版 ...
- SpringCloud OpenFeign的使用
SpringCloud OpenFeign的使用 是什么: 声明式http客户端. 目的: 使远程调用更简单 作用: 提供了http请求模板,仅需编写简单接口和插入注解,就可以定义好原始http请求的 ...