Made accessing JobCount thread safe

This commit is contained in:
dankito 2022-02-13 22:01:13 +01:00
parent 2563051082
commit aa532b864c
2 changed files with 7 additions and 4 deletions

View File

@ -58,6 +58,8 @@ kotlin {
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.3.2" implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.3.2"
implementation "co.touchlab:stately-concurrency:1.2.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
implementation "io.ktor:ktor-client-core:$ktorVersion" implementation "io.ktor:ktor-client-core:$ktorVersion"

View File

@ -1,5 +1,6 @@
package net.dankito.banking.fints.model package net.dankito.banking.fints.model
import co.touchlab.stately.concurrency.AtomicInt
import net.dankito.banking.fints.callback.FinTsClientCallback import net.dankito.banking.fints.callback.FinTsClientCallback
import net.dankito.banking.fints.log.IMessageLogAppender import net.dankito.banking.fints.log.IMessageLogAppender
import net.dankito.banking.fints.log.MessageContext import net.dankito.banking.fints.log.MessageContext
@ -26,7 +27,7 @@ open class JobContext(
) : MessageBaseData(bank, product), IMessageLogAppender { ) : MessageBaseData(bank, product), IMessageLogAppender {
companion object { companion object {
private var JobCount = 0 // this is not thread safe so job number may not be 100 % accurate private var JobCount = AtomicInt(0) // this variable is accessed from multiple threads, so make it thread safe
} }
@ -47,7 +48,7 @@ open class JobContext(
get() = ArrayList(_dialogs) // create a copy get() = ArrayList(_dialogs) // create a copy
protected open val jobNumber: Int = ++JobCount protected open val jobNumber: Int = JobCount.incrementAndGet()
protected open var dialogNumber: Int = 0 protected open var dialogNumber: Int = 0