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
| val lowPriorityThreadsDispatcherName = "low-priority-threads-dispatcher" | |
| val lowPriorityThreadsExecutionContext = play.libs.Akka.system.dispatchers.lookup(lowPriorityThreadsDispatcherName) | |
| Future { | |
| require(Thread.currentThread.getPriority == Thread.MIN_PRIORITY, s"current thread's priority should be ${Thread.MIN_PRIORITY} but it is ${Thread.currentThread.getPriority}") | |
| 1 + 1 // do something that would be executed on low pririty thread | |
| }(lowPriorityThreadsExecutionContext) |
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
| # Low priority threads protects system from CPU starvation. | |
| low-priority-threads-dispatcher { | |
| # For more details please see documentation of this class. | |
| type = akka.dispatch.PriorityThreadsDispatcher | |
| executor = "thread-pool-executor" | |
| # Priority of threads in this thread pool, should be between Thread.MIN_PRIORITY (which is 1) and Thread.MAX_PRIORITY (which is 10). | |
| thread-priority = 1 |
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
| 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) | |
| */ |
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
| package akka.dispatch | |
| /** | |
| * Composition over [[DefaultDispatcherPrerequisites]] that replaces thread factory with one that allow to configure thread priority. | |
| * | |
| * @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 PriorityThreadsDispatcherPrerequisites(prerequisites: DispatcherPrerequisites, newThreadPriority: Int) extends DefaultDispatcherPrerequisites( | |
| eventStream = prerequisites.eventStream, |
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
| package akka.dispatch | |
| import com.typesafe.config.Config | |
| object PriorityThreadsDispatcher { | |
| /** | |
| * Configuration key under which int value should be placed. | |
| */ | |
| val threadPriorityConfigKey = "thread-priority" | |
| } |
NewerOlder