logo

CuriousTab

CuriousTab

Discussion


Home Java Programming Threads Comments

  • Question
  • Which of the following will not directly cause a thread to stop?


  • Options
  • A. notify()
  • B. wait()
  • C. InputStream access
  • D. sleep()

  • Correct Answer
  • notify() 

    Explanation
    Option A is correct. notify() - wakes up a single thread that is waiting on this object's monitor.

    Option B is wrong. wait() causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.

    Option C is wrong. Methods of the InputStream class block until input data is available, the end of the stream is detected, or an exception is thrown. Blocking means that a thread may stop until certain conditions are met.

    Option D is wrong. sleep() - Causes the currently executing thread to sleep (temporarily cease execution) for a specified number of milliseconds. The thread does not lose ownership of any monitors.


    Threads problems


    Search Results


    • 1. Which method must be defined by a class implementing the java.lang.Runnable interface?

    • Options
    • A. void run()
    • B. public void run()
    • C. public void start()
    • D. void run(int priority)
    • Discuss
    • 2. Which method registers a thread in a thread scheduler?

    • Options
    • A. run();
    • B. construct();
    • C. start();
    • D. register();
    • Discuss
    • 3. Which two of the following methods are defined in class Thread?

      1. start()
      2. wait()
      3. notify()
      4. run()
      5. terminate()

    • Options
    • A. 1 and 4
    • B. 2 and 3
    • C. 3 and 4
    • D. 2 and 4
    • Discuss
    • 4. Which cannot directly cause a thread to stop executing?

    • Options
    • A. Calling the SetPriority() method on a Thread object.
    • B. Calling the wait() method on an object.
    • C. Calling notify() method on an object.
    • D. Calling read() method on an InputStream object.
    • Discuss
    • 5. Which two are valid constructors for Thread?

      1. Thread(Runnable r, String name)
      2. Thread()
      3. Thread(int priority)
      4. Thread(Runnable r, ThreadGroup g)
      5. Thread(Runnable r, int priority)

    • Options
    • A. 1 and 3
    • B. 2 and 4
    • C. 1 and 2
    • D. 2 and 5
    • Discuss
    • 6. Which class or interface defines the wait(), notify(),and notifyAll() methods?

    • Options
    • A. Object
    • B. Thread
    • C. Runnable
    • D. Class
    • Discuss
    • 7. Which will contain the body of the thread?

    • Options
    • A. run();
    • B. start();
    • C. stop();
    • D. main();
    • Discuss
    • 8. Assume the following method is properly synchronized and called from a thread A on an object B:

      wait(2000);

      After calling this method, when will the thread A become a candidate to get another turn at the CPU?


    • Options
    • A. After thread A is notified, or after two seconds.
    • B. After the lock on B is released, or after two seconds.
    • C. Two seconds after thread A is notified.
    • D. Two seconds after lock B is released.
    • Discuss
    • 9. What is the name of the method used to start a thread execution?

    • Options
    • A. init();
    • B. start();
    • C. run();
    • D. resume();
    • Discuss
    • 10. Which of the following will directly stop the execution of a Thread?

    • Options
    • A. wait()
    • B. notify()
    • C. notifyall()
    • D. exits synchronized code
    • Discuss


    Comments

    Avatar
    Veronazec
    Life

    Avatar
    Igordsd
    Ukraine

    Avatar
    Svetlurl
    Novyny

    Avatar
    Igorvac
    Ukraine

    Avatar
    Svetluec
    Novyny

    Avatar
    Igorxzh
    Ukraine

    Avatar
    Veronailb
    Life

    Avatar
    Leonxqz
    urenrjrjkvnm

    Avatar
    Leonshc
    urenrjrjkvnm

    Avatar
    Leonych
    urenrjrjkvnm

    Avatar
    Vilianawuz
    Novost

    Avatar
    Sergxiv
    Novost

    Avatar
    Vilianaeoe
    Novost

    Avatar
    Irintcq
    urenrjrjkvnm

    Avatar
    Irinwdk
    urenrjrjkvnm

    Avatar
    Evajsj
    Med

    Avatar
    Irinwca
    urenrjrjkvnm

    Avatar
    Evajpf
    Med

    Avatar
    Irinacs
    urenrjrjkvnm

    Avatar
    Evavsp
    Med

    Avatar
    Irinsxs
    urenrjrjkvnm

    Avatar
    Veronawvc
    urenrjrjkvnm

    Avatar
    Davidlrr
    coin

    Avatar
    Davidcac
    coin

    Avatar
    Eldarjwr
    coin

    Avatar
    Davidpik
    coin

    Avatar
    Vikizir
    urenrjrjkvnm

    Avatar
    Vikizeg
    urenrjrjkvnm

    Avatar
    Vikihde
    urenrjrjkvnm

    Avatar
    Viktorimym
    Cinema

    Avatar
    Viktoriddw
    Cinema

    Avatar
    Robapn
    Novost

    Avatar
    Viktorizyh
    Cinema

    Avatar
    Robinz
    Novost

    Avatar
    Robvrh
    Novost

    Avatar
    Robiin
    Novost


Enter a new Comment