肯定是E啦,线程由cpu随机调配,结果不能确定的

解决方案 »

  1.   

    QUESTION 61 Exhibit :
    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);//这个输出D
    25. }
    26. }
    27. }
    28. }.start();
    29. }
    30. }
    怎么都没答案,楼主是不是抄错啊?