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.
Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
Sandra Bachan wrote: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.
Only one thread can enter locked() at a time because it is synchronized. So how is set 6a 7a 6b 7b possible?
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg wrote:
There are two different objects of Lockdown class on which locked locked method would be called. So they won't block each other.
Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
Matthew Brown wrote:One thing to watch out for in this sort of question - sometimes they'll make the method static synchronized. In that case it synchronizes on the class, so both threads are locking on the same object, so you get different results. Don't let that catch you out!
Marriage Made in Heaven
http://www.youtube.com/user/RohitWaliaWedsSonia
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
OCPJP 6
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Ankit Garg wrote:No C is not the answer, the output "6a 7a 6b 7b" is possible...
OCPJP 6
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links