Last active
January 30, 2019 13:47
-
-
Save kermitas/aef9f9b8924fa9158091 to your computer and use it in GitHub Desktop.
Akka dispatcher with configurable priority for created threads.
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
package akka.dispatch | |
import com.typesafe.config.Config | |
object PriorityThreadsDispatcher { | |
/** | |
* Configuration key under which int value should be placed. | |
*/ | |
val threadPriorityConfigKey = "thread-priority" | |
} | |
/** | |
* Akka Dispatcher that creates thread with configurable priority. | |
* | |
* Example of configuration: | |
* | |
* low-priority-threads-dispatcher { | |
* type = akka.dispatch.PriorityThreadsDispatcher | |
* executor = "thread-pool-executor" | |
* threads-priority = 1 <--- here we set the priority, should be between Thread.MIN_PRIORITY (which is 1) and Thread.MAX_PRIORITY (which is 10) | |
* thread-pool-executor { | |
* core-pool-size-min = 0 | |
* core-pool-size-factor = 2.0 | |
* core-pool-size-max = 10 | |
* } | |
* } | |
* | |
* Two arguments constructor (the primary constructor) is automatically called by Akka when it founds: | |
* abcde-dispatcher { | |
* type = akka.dispatch.PriorityThreadsDispatcher <--- that is a class that Akka will instantiate | |
* ... | |
* } | |
* | |
* @param config passed automatically by Akka, should contains information about threads priority | |
* @param prerequisites passed automatically by Akka | |
*/ | |
class PriorityThreadsDispatcher(config: Config, prerequisites: DispatcherPrerequisites) | |
extends DispatcherConfigurator(config, new PriorityThreadsDispatcherPrerequisites(prerequisites, config.getInt(PriorityThreadsDispatcher.threadPriorityConfigKey))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment