Created
April 3, 2016 10:27
-
-
Save larroy/86c228d765b52a33ad1d737ae94a51cf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.{TimeUnit, ArrayBlockingQueue, ThreadPoolExecutor} | |
import scala.concurrent.ExecutionContext | |
object ThrottlingExecutionContext { | |
def apply(poolSize: Int, maxQueued: Int): ExecutionContext = { | |
val workQueue = new ArrayBlockingQueue[Runnable](maxQueued) { | |
override def offer(x: Runnable): Boolean = { | |
put(x) | |
true | |
} | |
} | |
ExecutionContext.fromExecutorService( | |
new ThreadPoolExecutor(poolSize, poolSize, 0L, TimeUnit.SECONDS, workQueue) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment