Added option to use a blocking mailbox with custom capacity

This commit is contained in:
Jonas Bonér 2010-08-21 10:45:00 +02:00
parent 60d16d91e0
commit fd69201728
5 changed files with 42 additions and 23 deletions

View file

@ -22,6 +22,7 @@ trait ThreadPoolBuilder extends Logging {
private var threadPoolBuilder: ThreadPoolExecutor = _
private var boundedExecutorBound = -1
protected var mailboxCapacity = -1
@volatile private var inProcessOfBuilding = false
private var blockingQueue: BlockingQueue[Runnable] = _
@ -154,6 +155,13 @@ trait ThreadPoolBuilder extends Logging {
this.boundedExecutorBound = bounds
}
/**
* Sets the mailbox capacity, -1 is unbounded
*/
def setMailboxCapacity(capacity: Int): Unit = synchronized {
this.mailboxCapacity = capacity
}
protected def procs(multiplier: Double): Int =
(Runtime.getRuntime.availableProcessors * multiplier).ceil.toInt