⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 boundedexecutor.java

📁 java concurrency in practice 源码. JAVA并发设计
💻 JAVA
字号:
package net.jcip.examples;import java.util.concurrent.*;import net.jcip.annotations.*;/** * BoundedExecutor * <p/> * Using a Semaphore to throttle task submission * * @author Brian Goetz and Tim Peierls */@ThreadSafepublic 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();        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -