多做题,通过考试没问题!

Java认证考试

睦霖题库>其他计算机考试>Java认证考试

public class SyncTest{   public static void main(String args) {    final StringBuffer s1= new StringBuffer();    final StringBuffer s2= new StringBuffer();    new Thread () {    public void run() {   synchronized(s1) {   s2.append(“A”);   synchronized(s2) {    s2.append(“B”);    System.out.print(s1);    System.out.print(s2);   }   }    }    }.start();   new Thread() {   public void run() {   synchronized(s2) {  s2.append(“C”);  synchronized(s1) {   s1.append(“D”);  System.out.print(s2);  System.out.print(s1);   }   }    }   }.start();   }   }   Which two statements are true? ()

  • A、 The program prints “ABBCAD”
  • B、 The program prints “CDDACB”
  • C、 The program prints “ADCBADBC”
  • D、 The output is a non-deterministic point because of a possible deadlock condition.
  • E、 The output is dependent on the threading model of the system the program is running on.
正确答案:B,D
答案解析:
进入题库查看解析

微信扫一扫手机做题