Hello,
Hope everyone is having a great weekend!
I am on the site education.oracle.com going through sample exam questions. It seems I spotted two errors, please clarify if my understanding is correct:
Given:
What is true about possible sets of output from this code?
a) Set 6a 7a 7b 8a and set 7a 7b 8a 8b are both possible.
b) Set 7a 7b 8a 8b and set 6a 7a 6b 7b are both possible. (*)
c) It could be set 7a 7b 8a 8b but set 6a 7a 6b 7b is NOT possible.
d) It could be set 7a 8a 7b 8b but set 6a 6b 7a 7b is NOT possible.
REFERENCE:
JLS 3.0
Option B is correct. Two different Lockdown objects are using the locked() method.
Error number 1
Only one
thread can enter locked() at a time because it is synchronized. So how is set
6a 7a 6b 7b possible? I can understand why the other choices are wrong, the jvm is multitasking among three Thread objects, rather than two Thread objects.
Error number 2
When I compiled this code, I got errors due to lines 3, 4 and 6; there was no accessor " . " between the class instance and the start() and getId() method. Below is the corrected code: