Threads! We commonly don’t deal with them directly on day-to-day work. What will the wolverineAdrenaline be?
Try to solve this challenge before seeing the answer below.
Answer: Remember, Threads execution is always uncertain and depends on the JVM. The order of execution is always random.
Conclusion: There is no exact result. The Threads will be executed randomly. wolverineAdrenaline could be 10, 11, 12, 13 or 14.
++Operation is not atomic. Result can be really different and can be corrupt. Why don’t you use AtomicInteger ?
++ is not atomic, but the result must be one of 10,11,12,13 or 14. It cannot be further corrupted