更多“wait()、notify()和notifyAll()方法是在哪个类中定义的()。”相关问题
  • 第1题:

    fooandbararepublicreferencesavailabletomanyotherthreads.fooreferstoaThreadandbarisanObject.Thethreadfooiscurrentlyexecutingbar.wait().Fromanotherthread,whichstatementisthemostreliablewaytoensuethatfoowillstopexecutingwait()?

    A.foo.notify();

    B.bar.notify();

    C.foo.notifyAll();

    D.Thread.notify();

    E.bar.notiFYAll();

    F.Object.notify();


    参考答案:E

  • 第2题:

    实现线程交互的wait()和notify()方法在______类中定义。


    正确答案:Object。
    Object。 解析:waitO和notify()方法是java.lang.object类的方法,是实现线程通信的两个方法。

  • 第3题:

    线程交互中不提倡使用的方法是( )。

    A.wait()

    B.notify()

    C.stop()

    D.notifyall()


    正确答案:C

  • 第4题:

    在JAVA中,调用一个对象的wait()方法后,() 

    • A、如果该对象的notify()方法已经被调用,则不会产生任何结果
    • B、在另外一个对象调用它的notify()活notifyAll()方法之前该对象一直被挂起
    • C、讲抛出一个异常
    • D、该对象的wait()方法与其他对象自动同步

    正确答案:B

  • 第5题:

    Which two CANNOT directly cause a thread to stop executing?()

    • A、 Calling the yield method.
    • B、 Calling the wait method on an object.
    • C、 Calling the notify method on an object.
    • D、 Calling the notifyAll method on an object.
    • E、 Calling the start method on another Thread object.

    正确答案:C,D

  • 第6题:

    wait()、notify()和notifyAll()方法是在哪个类中定义的()。

    • A、Thread
    • B、Runnable
    • C、Object
    • D、Event
    • E、Synchronize

    正确答案:C

  • 第7题:

    What can cause a thread to become non-runnable?()

    • A、 Exiting from a synchronized block.
    • B、 Calling the wait method on an object.
    • C、 Calling the notify method on an object.
    • D、 Calling the notifyAll method on an object.

    正确答案:B

  • 第8题:

    单选题
    What can cause a thread to become non-runnable?()
    A

     Exiting from a synchronized block.

    B

     Calling the wait method on an object.

    C

     Calling the notify method on an object.

    D

     Calling the notifyAll method on an object.


    正确答案: D
    解析: 暂无解析

  • 第9题:

    单选题
    void waitForSignal() {  Object obj = new Object();  synchronized (Thread.currentThread()) {  obj.wait();  obj.notify();  }  }  Which is true?()
    A

     This code may throw an InterruptedException.

    B

     This code may throw an IllegalStateException.

    C

     This code may throw a TimeoutException after ten minutes.

    D

     This code will not compile unless “obj.wait()” is replaced with “((Thread) obj).wait()”.

    E

     Reversing the order of obj.wait() and obj.notify() may cause this method to complete normally.

    F

     A call to notify() or notifyAll() from another thread may cause this method to complete normally.


    正确答案: F
    解析: 暂无解析

  • 第10题:

    单选题
    在Java中,调用一个对象的wait()方法后,()。
    A

    如果该对象的notify()方法已经被调用,则不会产生任何效果

    B

    在另外一个对象调用它的notify()或 notifyAll()方法之前该对象一直被挂起

    C

    将抛出一个异常

    D

    该对象的wait()方法与其他对象自动同步


    正确答案: B
    解析: 暂无解析

  • 第11题:

    单选题
    foo and bar are public references available to many other threads. foo refers to a Thread and bar is an Object. The thread foo is currently executing bar.wait(). From another thread, which statement is the most reliable way to ensue that foo will stop executing wait()?
    A

     foo.notify();

    B

     bar.notify();

    C

     foo.notifyAll();

    D

     Thread.notify();

    E

     bar.notiFYAll();

    F

     Object.notify();


    正确答案: C
    解析: 暂无解析

  • 第12题:

    多选题
    对于wait()方法,下面说法正确的是?()
    A

    wait()方法的调用者是同步锁对象

    B

    wait()方法使线程进入等待状态

    C

    调用同一锁对象的notify()或notifyAll()方法可以唤醒调用wait()方法等待的线程

    D

    调用wait()方法的线程会释放同步锁对象


    正确答案: A,B,C,D
    解析: 暂无解析

  • 第13题:

    Given:fooandbararepublicreferencesavailabletomanyotherthreads.fooreferstoaThreadandbarisanObject.Thethreadfooiscurrentlyexecutingbar.wait().Fromanotherthread,whatprovidesthemostreliablewaytoensurethatfoowillstopexecutingwait()?

    A.foo.notify();

    B.bar.notify();

    C.foo.notifyAll();

    D.Thread.notify();

    E.bar.notifyAll();


    参考答案:E

  • 第14题:

    下列说法中错误的一项是

    A.当线程需要在synchronized块中等待共享数据状态改变时,则需要调用wait()方法

    B.当线程需要在synchronized块中等待共享数据状态改变时,则需要调用notify()方法

    C.线程在synchronized块中执行完操作后,调用notify()方法通知正在等待的线程重新占有锁

    D.wait()和notify()可以实现线程的同步操作


    正确答案:B
    解析:本题考查线程间交互的概念。当线程进入synchronized块后,共享数据的状态并不一定满足该线程的需要,它要等待其他线程将共享数据改变为所需要的状态后才能继续执行,但由于此时它占有了该对象的锁,其他线程无法对共享数据进行操作,此时线程调用wait()方法进入等待状态,并且暂时释放共享数据的对象锁,其他线程可以获得该对象锁,进入synchronized块进行操作,操作完成之后,再调用notify()方法通知等待的线程重新占有锁,这样就实现了线程的同步操作。由此可见,wait()方法是线程需要在 synchronized块中等待共享数据状态改变时调用,而notify()方法是线程在synchronized块中执行完操作后调用,用来通知正在等待的线程重新占有锁,选项B的说法错误。

  • 第15题:

    java中下面哪些是Object类的方法()。

    • A、notify()
    • B、notifyAll()
    • C、sleep
    • D、wait()

    正确答案:A,B,D

  • 第16题:

    void waitForSignal() {  Object obj = new Object();  synchronized (Thread.currentThread()) {  obj.wait();  obj.notify();  }  }  Which is true?() 

    • A、 This code may throw an InterruptedException.
    • B、 This code may throw an IllegalStateException.
    • C、 This code may throw a TimeoutException after ten minutes.
    • D、 This code will not compile unless “obj.wait()” is replaced with “((Thread) obj).wait()”.
    • E、 Reversing the order of obj.wait() and obj.notify() may cause this method to complete normally.
    • F、 A call to notify() or notifyAll() from another thread may cause this method to complete normally.

    正确答案:B

  • 第17题:

    对于wait()方法,下面说法正确的是?()

    • A、wait()方法的调用者是同步锁对象
    • B、wait()方法使线程进入等待状态
    • C、调用同一锁对象的notify()或notifyAll()方法可以唤醒调用wait()方法等待的线程
    • D、调用wait()方法的线程会释放同步锁对象

    正确答案:A,B,C,D

  • 第18题:

    Which statements concerning the methods notify() and notifyAll() are true?  

    • A、Instances of class Thread have a method called notify().
    • B、A call to the method notify() will wake the thread that currently owns the monitor of the object.
    • C、The method notify() is synchronized.
    • D、The method notifyAll() is defined in class Thread.
    • E、When there is more than one thread waiting to obtain the monitor of an object, there is no way to be     sure which thread will be notified by the notify() method.

    正确答案:A,E

  • 第19题:

    单选题
    wait()、notify()和notifyAll()方法是在哪个类中定义的()。
    A

    Thread

    B

    Runnable

    C

    Object

    D

    Event

    E

    Synchronize


    正确答案: C
    解析: 暂无解析

  • 第20题:

    多选题
    Which two can directly cause a thread to stop executing?()
    A

    Exiting from a synchronized block.

    B

    Calling the wait method on an object.

    C

    Calling the notify method on an object.

    D

    Calling the notifyAll method on an object.

    E

    Calling the setPriority method on a thread object.


    正确答案: B,E
    解析: 暂无解析

  • 第21题:

    单选题
    Given:  foo and bar are public references available to many other threads, foo refers to a Thread and bar is an Object. The thread foo is currently executing bar.wait().  From another thread, what provides the most reliable way to ensure that foo will stop executing wait()?()
    A

    foo.notify();

    B

    bar.notify();

    C

    foo.notifyAll();

    D

    Thread.notify();

    E

    bar.notifyAll();

    F

    Object.notify();


    正确答案: C
    解析: 暂无解析

  • 第22题:

    单选题
    Given: foo and bar are public references available to many other threads. foo refers to a Thread and bar is anObject.  The thread foo is currently executing bar.wait().  From another thread,what provides the most reliable wayto ensure that foo will stop executing wait()?
    A

    foo.notify();

    B

    bar.notify();

    C

    foo.notifyAll();

    D

    Thread.notify();

    E

    bar.notifyAll();


    正确答案: C
    解析: 暂无解析

  • 第23题:

    多选题
    以下关于Object类的描述中,错误的是()。
    A

    Object类提供了wait,notify,notifyAll等函数用于线程间同步

    B

    Object类提供了clone,compare,delete,add,insert等函数用于对对象进行操作

    C

    Object类是所有自定义类的直接或间接父类,但不是系统类的父类

    D

    Object类定义了一些每个类都应该有的基本的成员变量和成员函数

    E

    Object类是其它一切类的直接或间接父类


    正确答案: C,A
    解析: 暂无解析

  • 第24题:

    填空题
    实现线程交互的wait()和notify()方法在____类中定义。

    正确答案: Object
    解析:
    Java Object类中的wait()方法就是使拥有当前对象(Object)的线程(Thread)放弃锁(release lock)进入睡眠状态。notify()方法通知在对象(Object)上因调用wait()方法而等待的某一进程启动。notifyAll()方法通知在对象(Object)上因调用wait()方法而等待的所有进程启动。这些进程根据优先级顺序执行。