Skip to content

Instantly share code, notes, and snippets.

@runarorama
Created May 4, 2015 20:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save runarorama/5af95832695e02426d32 to your computer and use it in GitHub Desktop.
Save runarorama/5af95832695e02426d32 to your computer and use it in GitHub Desktop.
Superstitious parent mode
import java.util.concurrent._
/**
* A thread pool for superstitious parent threads who
* know they shouldn't let their child threads back in the pool after
* eating, without waiting at least `crampFactor` milliseconds.
*/
object Superstitious {
def pool(crampFactor: Long) = new ThreadPoolExecutor(
0, Int.MaxValue, 60L, TimeUnit.SECONDS, new SynchronousQueue[Runnable]) {
override def afterExecute(r: Runnable, e: Throwable) = {
Thread.sleep(crampFactor)
super.afterExecute(r, e)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment