Created
May 4, 2015 20:51
-
-
Save runarorama/5af95832695e02426d32 to your computer and use it in GitHub Desktop.
Superstitious parent mode
This file contains 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._ | |
/** | |
* 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