Oracle
1Z0-804 · Question #88
Given: import java.util.concurrent.atomic.AtomicInteger; public class AtomicCounter { private AtomicInteger c = new AtomicInteger(0); public void increment() { // insert code here } } Which line of…
The correct answer is D. C.getAndIncrement (). public final int getAndIncrement() Atomically increment by one the current value.
Concurrency
Question
Given:
import java.util.concurrent.atomic.AtomicInteger; public class AtomicCounter { private AtomicInteger c = new AtomicInteger(0); public void increment() { // insert code here } } Which line of code, inserted inside the increment () method, will increment the value of c?
Options
- AC.addAndGet();
- Bc++;
- Cc = c+1;
- DC.getAndIncrement ();
How the community answered
(55 responses)- A13% (7)
- B7% (4)
- C4% (2)
- D76% (42)
Explanation
public final int getAndIncrement() Atomically increment by one the current value.
Topics
#AtomicInteger#getAndIncrement#atomic operations#thread-safe increment
Community Discussion
No community discussion yet for this question.