Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


neelam
Thread method
1 Answer(s)      4 years and 6 months ago
Posted in : Java Interview Questions


What is the purpose of the wait(), notify(), and notifyAll() methods?

Advertisement
View Answers

October 19, 2010 at 4:23 PM


Hi,

 Here is the answer.

Java includes an elegant inter process communication mechanism via the wait( ), notify( ), and notifyAll( ) methods.

These methods are implemented as final methods in Object, so all classes have them. All three methods can be called only from within a synchronized method.

wait() tells the calling thread to give up the monitor and go to sleep until some other thread enters the same monitor and calls notify( ).

notify() wakes up the first thread that called wait( ) on the same object.

notifyAll() wakes up all the threads that called wait( ) on the same object. The highest priority thread will run first.

Thanks.



Related Tutorials/Questions & Answers:
Thread method
Thread method  What is the purpose of the wait(), notify(), and notifyAll() methods
Java Thread : toString() method
Java Thread : toString() method In this section we are going to describe toString() method with example in java thread. toString() method : If you want... and thread group. Example :In this example we are using toString() method
Advertisements
Java Thread : setDaemon() method
Java Thread : setDaemon() method In this section we are going to describe setDaemon() method with example in java thread. Daemon Thread  : In Java.... public final void setDaemon(boolean on) : This method sets user thread either
Java Thread : isAlive() method
Java Thread : isAlive() method In this tutorial you will learn how to use isAlive() method in java thread. isAlive() method : When you are running many... of your thread dead. This can be checked by using method Thread.isAlive(). boolean
Java Thread : isDaemon() method
Java Thread : isDaemon() method In this section we are going to describe isDaemon() method with example in java thread. Daemon Thread  : In Java Thread, daemon threads are used to perform services for user threads. You can
sleep method in thread java program
sleep method in thread java program  How can we use sleep method... method .After that interval thread will awake.   public class test... Description:- In this thread example ,we have used sleep method. we are passing
Java Thread : yield() method
Java Thread : yield() method In this section we are going to describe yield() method with example in java thread. yield() Method: When you want to stop...() method of Thread. public static void yield() - This method pauses
Java Thread : run() method
Java Thread : run() method In this section we are going to describe run() method with example in java thread. Thread run() : All the execution code...() : By extending the Thread class, run() method is overridden and put all
Java Thread : stop() method
Java Thread : stop() method In this section we are going to describe stop() method with example in java thread. stop() method : Java thread provides method stop to stop any running thread. It is deprecated  as it causes
Java Thread : sleep() method
Java Thread : sleep() method In this section we are going to describe sleep() method with example in java thread. sleep() method : Suppose you want to stop your thread for a specific time period, you can use sleep() method
(help me) use wait() and notify() method in Thread.
(help me) use wait() and notify() method in Thread.   we have to create 3 classes..1 is the main class, 1 is Thread UUM class, and another one is Thread Sintok class...we have to use wait(); and notify(); to comes out
is having any method same behavior of Single thread model in java?
is having any method same behavior of Single thread model in java?  is having any method same behavior of Single thread model in java
is having any method same behavior of Single thread model in java?
is having any method same behavior of Single thread model in java?  is having any method same behavior of Single thread model in java
is having any method same behavior of Single thread model in java?
is having any method same behavior of Single thread model in java?  is having any method same behavior of Single thread model in java
is having any method same behavior of Single thread model in java?
is having any method same behavior of Single thread model in java?  is having any method same behavior of Single thread model in java
Thread
instance the thread is in this state but before the start() method invocation... after the invoking of start() method but a thread can return to this state after... ? A thread can be considered dead when its run() method completes. If any thread comes
thread
thread  can parent thread be dead if child thread is not dead
Thread
Thread  what is the use of thread
Thread
Thread  Thread Life Cycle
Thread
Thread  Explain two ways of creating thread in java. Explain at three methods of thread class.   Java Create Thread There are two main ways of creating a thread. The first is to extend the Thread class and the second
Thread
to the thread constructor eventhough we had created only one thread and if you say we have added to point to the current thread then why we have not added this in the following line "s=s1" Pls reply...... class MyThread extends Thread { Thread
Java Sleep Thread
Java Thread sleep() is a static method. It sleeps the thread for the given time in milliseconds. It is used to delay the thread. It is used in Applet or GUI programming for animation Java Sleep Thread Example public class
Thread
Thread  class Extender extends Thread { Extender(Runnable run...(); } public void run(){ System.out.println("Extender Thread is Started :"); //new Thread(new Implementer()).start(); } } class Implementer
Thread
Thread  what happen when we call the Wait(),Notify() and NotifyAll() methods in the Thread
Thread
Thread  will this code work..? class A extends Thread { public...=" + i); } public static void main(string args[]) { A a = new A(); Thread t = new thread(a); t.start(); } } Is it possible to run above program with out
Thread
Thread  Write a Java program to create three theads. Each thread should produce the sum of 1 to 10, 11 to 20 and 21to 30 respectively. Main thread....   Java Thread Example class ThreadExample{ static int
Java Thread destroy
Java Thread destroy In this tutorial, we are using Thread.destroy() method... method to destroy the thread. In general, Thread.destroy() is dangerous...() : This method destroy your thread without any cleanup. The locked monitor remains lock
Thread
Thread   there are two threads running at a time.. when am updating a values in database. both thread halt and stop for moment till it get updated into database... so i dnt want thread to get halts for tht moment of period. whats
Java Current Thread
() method to find the current thread name. Thread.currentThread() : Thread class provides method to display the current running thread. It is static Thread method so that there is no need to call a reference to a Thread object
Java Thread Context
classloader to set a thread using Thread.setContextClassLoader() method... Thread Context       The Thread Context is required by the current thread from the group
Thread
us to handle them. We can also use throws clause on the surrounding method
Advertisements
 

 

 

DMCA.com