Skip to content

Instantly share code, notes, and snippets.

@kermitas
Created July 6, 2015 11:19
Show Gist options
  • Select an option

  • Save kermitas/d125c1d6e8ff555832d5 to your computer and use it in GitHub Desktop.

Select an option

Save kermitas/d125c1d6e8ff555832d5 to your computer and use it in GitHub Desktop.
ThreadFactory with configurable priority.
package akka.dispatch
import java.util.concurrent.ThreadFactory
/**
* Composition over the [[DispatcherPrerequisites.threadFactory]] that set priority for newly created threads.
*
* @param newThreadPriority priority that will be set to each newly created thread
* should be between Thread.MIN_PRIORITY (which is 1) and Thread.MAX_PRIORITY (which is 10)
*/
class PriorityThreadFactory(prerequisites: DispatcherPrerequisites, newThreadPriority: Int) extends ThreadFactory {
override def newThread(r: Runnable): Thread = {
val newThread = prerequisites.threadFactory.newThread(r)
newThread.setPriority(newThreadPriority)
newThread
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment