博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用信号量来 限制无边界池子与队列
阅读量:7231 次
发布时间:2019-06-29

本文共 829 字,大约阅读时间需要 2 分钟。

  使用信号量来 限制无边界池子与队列

 

public class BoundedExecutor {     private final Executor exec;     private final Semaphore semaphore;     public BoundedExecutor(Executor exec, int bound) {            this. exec = exec;            this. semaphore = new Semaphore(bound);     }     public void submitTask( final Runnable command) throws InterruptedException {            semaphore.acquire();            try {                 exec. execute(new Runnable() {                      public void run() {                            try {                                command.run();                           } finally {                                 semaphore.release();                           }                     }                });           } catch (RejectedExecutionException e) {                 semaphore.release();           }     }}

 

转载地址:http://dwpfm.baihongyu.com/

你可能感兴趣的文章
全面理解 git
查看>>
Activiti Modeler初探实践
查看>>
NET Core Kestrel部署HTTPS使用SSL证书
查看>>
20165320 结对编程学习第一周
查看>>
[转] 池子法 邻接表建图
查看>>
【前端积累】SEO 学习
查看>>
tt安装与配置
查看>>
software testing HW02
查看>>
linux .net mono方案测试记录与报告(一)
查看>>
某未被少林寺吞并的小寺庙师徒的经典对话
查看>>
IT兄弟连 JavaWeb教程 JSP内置对象1
查看>>
IT兄弟连 JavaWeb教程 JSP内置对象经典案例
查看>>
XCode环境变量及路径设置 解决头文件找不到的问题
查看>>
[Go]链表的相关知识
查看>>
C# Json数据反序列化为Dictionary并根据关键字获取指定值1
查看>>
jS Ajax 上传文件报错"Uncaught TypeError: Illegal invocation"
查看>>
javascript、jquery获取网页的高度和宽度
查看>>
面向对象---代码练习(以车为案例)
查看>>
C#趋势图(highcharts插件)
查看>>
stm32的flash编程
查看>>