单选题

假设如下代码中,若t1线程在t2线程启动之前已经完成启动。代码的输出是()...

发布于 2022-03-03 16:47:04

假设如下代码中,若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()

}


登录后免费查看答案
关注者
0
被浏览
20
知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看