jjzjj

BoundedExecutor

全部标签

Java 并发实践 : race condition in BoundedExecutor?

在《Java并发实践》一书中,BoundedExecutor的实现有些奇怪。当有足够多的线程在执行器中排队或运行时,它应该通过阻塞提交线程来限制向执行器提交任务。这是实现(在catch子句中添加缺少的重新抛出之后):publicclassBoundedExecutor{privatefinalExecutorexec;privatefinalSemaphoresemaphore;publicBoundedExecutor(Executorexec,intbound){this.exec=exec;this.semaphore=newSemaphore(bound);}publicvoi