可学答题网 > 问答 > SCJP程序员认证考试题库
目录: 标题| 题干| 答案| 搜索| 相关
问题

public class SyncTest{&ensp


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.
参考答案
参考解析:
分类:SCJP程序员认证考试题库
相关推荐

1、10. public class Class

10. public class ClassA { 11. public void methodA() { 12. ClassB classB = new ClassB()...

2、public class SyncTest 

public class SyncTest { private int x; private int y; private synchronized void setX( int&en...

3、public class X { 

public class X { public static void main(String [] args) { try { badMethod(); System.out.p...

4、10. public class Class

10. public class ClassA { 11. public void count(int i) { 12. count(++i); 13. } 14.&en...

5、public class SyncTest 

public class SyncTest ( private int x; private int y; private synchronized void setX (int&e...

6、public class SyncTest 

public class SyncTest (  private int x;  private int y;  private synchronized void&ensp...