Why is the answer to this letter b? (question and answer below) I understand 7a 7b 8a 8b, since the method is synchronized hence only one thread could execute at a time, but why is 6a 7a 6b 7b acceptable as well? shouldn't the second thread wait for the first thread to finish with the method?
public class Lockdown implements Runnable {
public static void main(String[] args) {
new Thread(new Lockdown()).start();
new Thread(new Lockdown()).start();
}
public void run() { locked(Thread.currentThread().getId()); }
synchronized void locked(long id) {
System.out.print(id + "a ");
System.out.print(id + "b ");
}
}
b) Set 7a 7b 8a 8b and set 6a 7a 6b 7b are both possible. (*)