Only one thread t1 has access to Test.x.
Only one thread t2 has access to Test.xObj.
Monitor (implicit synchronization) of Instance class Test is not used.
There is no thread interference at all here.
Even if we remove keyword volatile and exchange optimistic locking AtomicInteger variable regular Integer the thread execution order is generally unpredictable because of not absolute contract with underlying OS in order to perform threads scheduling.
n the given code, two threads (t1 and t2) are running concurrently and printing the values of x and xObj, respectively. The execution order of the threads can vary due to their concurrent nature. Here's the breakdown:
Thread 1 (t1) is operating on the volatile int x variable. It increments x from 1 to 2 as part of the while (t.x < 3) loop.
Thread 2 (t2) is operating on the AtomicInteger xObj. It increments xObj from 1 to 2 and then to 3 as part of the while (t.xObj.get() < 3) loop.
This section is not available anymore. Please use the main Exam Page.1z0-829 Exam Questions
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
1 month, 1 week agoNaoufal18
4 months, 1 week agoUteman
10 months agoxplorerpj
10 months, 3 weeks agominhdev
12 months agojames2033
1 year, 2 months agoSamps
1 year, 2 months ago