我正在使用 JMH 来测试我的项目的一些功能。当我尝试将 @GroupThreads 与 AtomicInteger 一起使用时,我无法重置 AtomicInteger,它只会随着时间的推移而增加。我还尝试使用 if else 检查和重置 AtomicInteger 但不能。你能给我一些关于我的问题的建议吗?非常感谢。
class JMHSample_15_Asymmetric {
private var counter: AtomicInteger = _
@Setup
def up() {
counter = new AtomicInteger
}
@Benchmark
@Group("g")
@GroupThreads(3)
def inc: Int = {
counter.compareAndSet(10,-1)
counter.incrementAndGet
}
@Benchmark
@Group("g")
@GroupThreads(1)
def get: Int = {
println("Counter --> "+ counter.get)
counter.get
}
}