问题详情

public class TwoThreads {  private static Object resource = new Object();  private static void delay(long n) {  try { Thread.sleep(n); }  catch (Exception e) { System.out.print(”Error “); }  }  public static void main(String[] args) {  System.out.print(”StartMain “);  new Thread1().start();  delay(1000);  Thread t2 = new Thread2();  t2.start();  delay(1000);  t2.interrupt  delay(1000);  System.out.print(”EndMain “);  }  static class Thread 1 extends Thread {  public void run() {  synchronized (resource) {  System.out.print(”Startl “);  delay(6000);  System.out.print(”End1 “);  }  }  }  static class Thread2 extends Thread {  public void run() {  synchronized (resource) {  System.out.print(”Start2 “);  delay(2000);  System.out.print(”End2 “);  }  }  }  }  Assume that sleep(n) executes in exactly m milliseconds, and all other code executes in an insignificant amount of time. What is the output if the main() method is run?() 


A、 Compilation fails.

B、 Deadlock occurs.

C、 StartMain Start1 Error EndMain End1

D、 StartMain Start1 EndMain End1 Start2 End2

E、 StartMain Start1 Error Start2 EndMain End2 End1

F、StartMain Start1 EndMain End1 Start2 Error End2

时间:2023-03-06 11:23 关键词: SCJP程序员认证考试

答案解析

F
相关问题