Sobes.tech
Junior — Senior

Simultaneous increment of two counters using CountDownLatch

livecode

Task condition

The program creates 100,000 tasks, which are executed simultaneously in a pool of 100 threads. Each task increments two shared counters — incA and incB. To wait for all tasks to complete before printing the results, a CountDownLatch object is used. It is expected that the printed values at the end of the program will be 100000 for both counters, assuming no race conditions occur.