首页 试题广场 > 试题详情
单选题

假设如下代码中,若t1线程在t2线程启动之前已经完成启动。代码的输出是() public static void main(String[]args)throws Exception {? ? final Object obj = new Object();? ? Thread t1 = new Thread() {? ? ? ? public void run() {? ? ? ? ? ? synchronized (obj) {? ? ? ? ? ? ? ? try {? ? ? ? ? ? ? ? ? ? obj.wait();? ? ? ? ? ? ? ? ? ? System.out.println("Thread 1 wake up.");? ? ? ? ? ? ? ? } catch (InterruptedException e) {? ? ? ? ? ? ? ? }? ? ? ? ? ? }? ? ? ? }? ? };? ? t1.start();? ? Thread.sleep(1000);//We assume thread 1 must start up within 1 sec.? ? Thread t2 = new Thread() {? ? ? ? public void run() {? ? ? ? ? ? synchronized (obj) {? ? ? ? ? ? ? ? obj.notifyAll();? ? ? ? ? ? ? ? System.out.println("Thread 2 sent notify.");? ? ? ? ? ? }? ? ? ? }? ? };? ? t2.start();}

  • A.Thread 1 wake upThread 2 sent notify.
  • B.Thread 2 sent notify.Thread 1 wake up
  • C.A、B皆有可能
  • D.程序无输出卡死
提交并查看答案
下一题 上一题
Ke星伙伴们的回答/ 4个回答
  • SWYY 1楼

    ******
    发表时间:2017-08-11 10:45:17

  • ゞ夜色 2楼

    ******
    发表时间:2017-08-18 08:35:45

  • sunnydd 3楼

    ******
    发表时间:2018-01-05 11:11:00

  • 子杰小同学 4楼

    ******
    发表时间:2018-02-09 09:56:43

关闭
关闭
QQ
交流群
邀请
好友
App
下载
意见
反馈
返回
顶部