Given the code fragment:
andWhich is true?
Given the code fragment:
andWhich is true?
The program starts two threads, t1 and t2. The first thread (t1) increments and prints the volatile integer x variable until it is less than 3, while the second thread (t2) increments and prints the AtomicInteger xObj until it is less than 3. Since both increment and print their respective values independently, their outputs can interleave in any order, thus, the program prints t1: 1: t2 : 1: t1 : 2 : t2 : 2: in random order.
// Result: // t2 : 1 : t2 : 2 : t1 : 1 : t1 : 2 : // t1 : 1 : t2 : 1 : t2 : 2 : t1 : 2 : // t1 : 1 : t2 : 1 : t1 : 2 : t2 : 2 : // t1 : 1 : t2 : 1 : t1 : 2 : t2 : 2 :
A is correct tested
A is correct
A is the correct answer. The below gets printed in random Order. t2:1: t2:2: t1:1: t1:2:
A is correct answer