thread related

thread related

View Answers

December 23, 2008 at 6:30 AM

Hi friend,

Two threads can communicate with each other using
the wait() and notify() , notifyAl() methods. wait()
method tells the thread to wait until another threads
calls notify() method.

The wait() method causes the current thread to wait
(possibly forever) until another thread notifies it of a
condition change. We use wait() in conjunction with notify
() or notifyAll() to coordinate the activities of multiple
threads using the same resources.

The notifyAll() method notifies all the threads waiting on
the monitor held by the current thread and wakes them up.
Typically, one of the waiting threads will grab the monitor
and proceed.

public class WaitMethod extends Thread{
String st="Hello";
public static void main(String args[]) {
WaitMethod wait=new WaitMethod();
wait.start();
new Example(wait);
}
public void run(){
try {
synchronized(this){
wait();
System.out.println("value is :"+st);
}
}catch(Exception e){}
}
public void valchange(String st){
this.st=st;
try {
synchronized(this) {
notifyAll();
}
}catch(Exception e){}
}
}
class Example extends Thread{
WaitMethod wait;
Example(WaitMethod wait) {
this.wait=wait;
start();
}
public void run(){
try{
System.out.println("Value is changed to: "+wait.st);
wait.valchange("Hello World");
}catch(Exception e){}
}
}

Thanks









Related Tutorials/Questions & Answers:
related to multiple thread....!!!!
related to multiple thread....!!!!  Write a Java program, which creates a linklist for Employees info viz. EmpID, EmpName, EmpAge. All operations should be performed on the linklist, like; Create, Add, Delete, Update, Size
thread related - Java Interview Questions
thread related  Hi, Plz tell me how two thread will communicate...() , notifyAl() methods. wait() method tells the thread to wait until another threads calls notify() method. The wait() method causes the current thread
Advertisements
what is jvm instance, how is it created, how is related to thread?
what is jvm instance, how is it created, how is related to thread?  what is jvm instance, how is it created, how is related to thread
thread
thread  can parent thread be dead if child thread is not dead
Thread
Thread  Thread Life Cycle
Thread
Thread  what is the use of thread
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
Thread  What is multi-threading? Explain different states of a thread... processor system. States of Thread: New state ? After the creations of Thread instance the thread is in this state but before the start() method invocation
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
Thread
Thread  what happen when we call the Wait(),Notify() and NotifyAll() methods in the Thread
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  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
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
StringBuffer related.
StringBuffer related.  how to make StringBuffer as immutable
related to database
related to database  how to override existing values in table? when user enters his updated data through query
Related to Histogram
Related to Histogram  hi this is srinivasrao. In my project i have to display using chart for that i want to use histogram. k chart displayed but the values given by me is not related display chart so please give the code if u
related to java
related to java  what is mean of }); in java.i know that } is used to close a block of statement,) is used to close a statement and ";"is used after close a statement but i can not usderstood the use of }); together in a java
Related Questions
Related Questions  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: Related Questions... "Related Questions". Also tell me which is the good training courses
Related to Project
Related to Project  how speech to text project can be make in java? Please tell me the coding part therapeutically i know i have to use java speech api which offer two technology 1. speech recognization 2. speech syenthesis
Related to XML
Related to XML  I have made a web application which send the SMS, i have provided the url in which i have to save the msg and the number's(to whom the message to be send).After fetching the message and numbers i was keeping
Related to XML
Related to XML  I have made a web application which send the SMS, i have provided the url in which i have to save the msg and the number's(to whom the message to be send).After fetching the message and numbers i was keeping
Thread in java
Thread in java  which method will defined in thread class
Daemon thread
Daemon thread  what is need of daemon thread
java Thread
java Thread  what is purpose of Thread
Daemon thread
Daemon thread  what is need of daemon thread
Java thread
Java thread  How can a dead thread be restarted?  A dead thread cannot be restarted
Thread restart
Thread restart  hello,, can dead thread restart?   hii,ADS_TO_REPLACE_1 A dead Thread can't restart not even by calling start() again on that object
Java thread
Java thread  What's the difference between a thread's start() and run() methods
Java thread
Java thread  What is the difference between process and thread
Thread method
Thread method  What is the purpose of the wait(), notify(), and notifyAll() methods
Java thread
Java thread  What invokes a thread's run() method
Java thread
Java thread  What are the ways in which you can instantiate a thread
Java thread
Java thread  What are the high-level thread states
Demon thread
Demon thread  What is demon thread? why we need Demon thread?  ... there are daemon thread by killing them abruptly.Any thread can be a daemon thread... = window.adsbygoogle || []).push({}); http://www.roseindia.net/java/thread/daemon
Thread scheduling
Thread scheduling  What is the algorithm used in Thread scheduling?  Java uses fixed-priority scheduling algorithms to decide which thread... on the basis of their priority relative to other Runnable threads. The thread
ModuleNotFoundError: No module named 'related'
ModuleNotFoundError: No module named 'related'  Hi, My Python... 'related' How to remove the ModuleNotFoundError: No module named 'related... to install padas library. You can install related python with following command
daemon thread
daemon thread  hello, What is a daemon thread?   hello,ADS_TO_REPLACE_1 These are the threads which can run without user intervention. The JVM can exit when there are daemon thread by killing them abruptly
Need the Following MobileApplication Related Code
Need the Following MobileApplication Related Code  Hi, I need java coding for the following requirements in Collections.. Mobile Subscriber name...: and one Daemon Thread class need's to run while doing the above operations and if you
Create Thread by Extending Thread
Create Thread by Extending Thread This section explain how to create thread by extending Thread class in java. Extending Thread : You can create thread by extending Thread class and then by creating instance of that class you can
Java thread
Java thread  Why do threads block on I/O?   When a thread... and in that time some other thread which is not waiting for that IO gets a chance to execute.If any input is not available to the thread which got suspended for IO
Dumps related to weblogic certification
Dumps related to weblogic certification   I want to perform the weblogic certification exam code 1z0-110. Can anybody please provide me the dumps related to 1z0-110 Thanks in advance
Related to weblogic server8.1
Related to weblogic server8.1  hi Everybody, i have write a simple servlet program and deploy on weblogic8.1 server. when I'm running this app. when...) at java.lang.Thread.startThreadFromVM(Ljava/lang/Thread;)V(Unknown Source) plz tell me
Thread in Nutshell
Thread in Nutshell  Hi, I m confused about what is called a thread actually in a program. There are many answer to this question on the web...; Please go through the following link: Thread Tutorials
Java and jvm related question
Java and jvm related question  What is difference between java data types and jvm data types
question related to overloading
question related to overloading  what is difference between function overloading & method overloading
question related to overloading
question related to overloading  what is difference between function overloading & method overloading
Main Thread and Child Thread
and Child Threads used in Programming. Main thread is automatically created when program runs. Child Thread gets created by the main thread . Java Main Thread Example public class mainchild implements Runnable { Thread t1
Thread concept
Thread concept  Everytime when i run a multithread program it gives... in advance friends. Happy new year!!!!! class Newthread3 implements Runnable{ Thread t; String name; Newthread3(String threadname){ name=threadname; t=new Thread
Java Related Question
class SynchronizedModel extends Thread { static String msg[]={"Welcome... args[]) { SynchronizedModel s=new SynchronizedModel("Thread 1"); s.start(); SynchronizedModel s1=new SynchronizedModel("Thread 2"); s1.start

Ads