SpringBoot 接口并发限制(Semaphore)(springboot并发数)

  本篇文章为你整理了SpringBoot 接口并发限制(Semaphore)(springboot并发数)的详细内容,包含有springboot设置并发连接数 springboot并发数 springboot并发吞吐量 springboot 并发调优 SpringBoot 接口并发限制(Semaphore),希望能帮助你了解 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并发数)的详细内容,想要了解更多 SpringBoot 接口并发限制(Semaphore)的内容,请持续关注盛行IT软件开发工作室。

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: