华企号 元宇宙 SpringBoot 接口的并发限制

SpringBoot 接口的并发限制

@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

作者: 华企网通李铁牛程序员

我是程序员李铁牛,热爱互联网软件开发和设计,专注于大数据、数据分析、数据库、php、java、python、scala、k8s、docker等知识总结。15889726201 我的座右铭:"业精于勤荒于嬉,行成于思毁于随"
上一篇
下一篇

发表回复

联系我们

联系我们

028-84868647

在线咨询: QQ交谈

邮箱: tech@68v8.com

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部