Hello Ranchers!.I was able to understand the deadlock situation down under but was not able to understand how the second answer is B.Could some one explain please?The second answer is
B. The program prints �CDDACB� code:
---------------------------------------------------------------------------
1. public class SyncTest{
2. public static void main(
String[] args) {
3. final StringBuffer s1= new StringBuffer();
4. final StringBuffer s2= new StringBuffer();
5. new
Thread () {
6. public void run() {
7. synchronized(s1) {
8. s2.append(�A�);
9. synchronized(s2) {
10. s2.append(�B�);
11. System.out.print(s1);
12. System.out.print(s2);
13. }
14. }
15. }
16. }.start();
17. new Thread() {
18. public void run() {
19. synchronized(s2) {
20. s2.append(�C�);
21. synchronized(s1) {
22. s1.append(�D�);
23. System.out.print(s2);
24. System.out.print(s1);
25. }
26. }
27. }
28. }.start();
29. }
30. }
--------------------------------------------------------------------------
Thanks in Advance