Skip to content

Commit bb18849

Browse files
committed
append atomic property setting on QueryCountPerRequest Object
1 parent 6fd49c0 commit bb18849

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group = "hyeon9mak"
11-
version = "2.2.0-spring-boot-3"
11+
version = "2.2.1-spring-boot-3"
1212

1313
java {
1414
toolchain {

src/main/java/hyeon9mak/multidatasourcequerycounter/QueryCountPerRequest.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@ package hyeon9mak.multidatasourcequerycounter
22

33
import org.springframework.stereotype.Component
44
import org.springframework.web.context.annotation.RequestScope
5+
import java.util.concurrent.atomic.AtomicInteger
6+
import java.util.concurrent.atomic.AtomicLong
7+
58

69
@RequestScope
710
@Component
811
data class QueryCountPerRequest(
912
var apiUrl: String = "",
10-
var totalQueryCount: Int = 0,
11-
var totalQueryMilliSeconds: Long = 0L,
13+
private var _totalQueryCount: AtomicInteger = AtomicInteger(0),
14+
private var _totalQueryMilliSeconds: AtomicLong = AtomicLong(0L),
1215
) {
16+
val totalQueryCount: Int
17+
get() = _totalQueryCount.get()
18+
19+
val totalQueryMilliSeconds: Long
20+
get() = _totalQueryMilliSeconds.get()
21+
1322
fun incrementQueryCount(executionMilliSeconds: Long) {
14-
totalQueryCount++
15-
totalQueryMilliSeconds += executionMilliSeconds
23+
_totalQueryCount = AtomicInteger(_totalQueryCount.incrementAndGet())
24+
_totalQueryMilliSeconds = AtomicLong(_totalQueryMilliSeconds.addAndGet(executionMilliSeconds))
1625
}
1726
}

0 commit comments

Comments
 (0)