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 "co.touchlab:stately-concurrency:1.2.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion"
implementation "io.ktor:ktor-client-core:$ktorVersion"

View File

@ -1,5 +1,6 @@
package net.dankito.banking.fints.model
import co.touchlab.stately.concurrency.AtomicInt
import net.dankito.banking.fints.callback.FinTsClientCallback
import net.dankito.banking.fints.log.IMessageLogAppender
import net.dankito.banking.fints.log.MessageContext
@ -26,7 +27,7 @@ open class JobContext(
) : MessageBaseData(bank, product), IMessageLogAppender {
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,14 +48,14 @@ open class JobContext(
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
open fun startNewDialog(closeDialog: Boolean = true, dialogId: String = DialogContext.InitialDialogId,
versionOfSecurityProcedure: VersionDesSicherheitsverfahrens = VersionDesSicherheitsverfahrens.Version_2,
chunkedResponseHandler: ((BankResponse) -> Unit)? = dialog.chunkedResponseHandler) : DialogContext {
versionOfSecurityProcedure: VersionDesSicherheitsverfahrens = VersionDesSicherheitsverfahrens.Version_2,
chunkedResponseHandler: ((BankResponse) -> Unit)? = dialog.chunkedResponseHandler) : DialogContext {
val newDialogContext = DialogContext(closeDialog, dialogId, chunkedResponseHandler)