continue
jumps to the next iteration.
They both are not same. Same should be
if (atomicBoolean1.get() == false && atomicBoolean2.get() == true) {
if (!atomicBoolean1.compareAndSet(false, true)) {
continue;
}
}
문제
If I do this, my program works very fine:
if (atomicBoolean1.get() == false && atomicBoolean2.get() == true
&& !atomicBoolean1.compareAndSet(false, true)) {
continue;
}
Now if I do this, everything breaks:
if (atomicBoolean1.get() == false && atomicBoolean2.get() == true) {
continue;
}
if (!atomicBoolean1.compareAndSet(false, true)) {
continue;
}
Am I getting insane?
해결책
continue
jumps to the next iteration.
They both are not same. Same should be
if (atomicBoolean1.get() == false && atomicBoolean2.get() == true) {
if (!atomicBoolean1.compareAndSet(false, true)) {
continue;
}
}
다른 팁
Actually you are not doing exactly similar things in above 2 cases.
In case1,
atomicBoolean1.get() == false && atomicBoolean2.get() == true
if above 2 conditions satisfied only,
atomicBoolean1.compareAndSet(false, true)
function is calling.
But in case2,
atomicBoolean1.get() == false && atomicBoolean2.get() == true
if above 2 conditions satisfied, it will go back to loop start. so will not call
atomicBoolean1.compareAndSet(false, true)
If those 2 conditions failed only, it will call
atomicBoolean1.compareAndSet(false, true)
I think, I may cause any problem.
Lets give more details about your program and what you are trying to do. It may help to figure out the issue.