Skip to content
Snippets Groups Projects
Verified Commit f59ef65d authored by Jan-Niclas Strüwer's avatar Jan-Niclas Strüwer
Browse files

updated taskmanager to use a fixed size custom threadpool

parent 808dfd1b
No related branches found
No related tags found
No related merge requests found
......@@ -22,6 +22,10 @@ class TaskManager : CoroutineScope {
// TODO: this could be dangerous to give it unlimited memory
private val tasks = Channel<String>(Channel.UNLIMITED)
private val numCores = Runtime.getRuntime().availableProcessors()
// use a fixed size thread pool context with numCores threads
private val threadPoolContext = newFixedThreadPoolContext(numCores, "TaskManagerWorker")
private val logger = getLogger(javaClass)
@PostConstruct
......@@ -33,7 +37,8 @@ class TaskManager : CoroutineScope {
}
}
private fun launchWorker(id: Int) = launch {
private fun launchWorker(id: Int) = launch(threadPoolContext) {
for (task in tasks) {
launch {
logger.debug("[${Thread.currentThread().name}] Processor #$id received $task")
......@@ -57,6 +62,7 @@ class TaskManager : CoroutineScope {
@PreDestroy
fun stop() {
job.cancel()
threadPoolContext.close()
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.