Awe Joey

Greenhorn
+ Follow
since Nov 15, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Awe Joey

it's still not working I tried creating one instance of the gets class:

===========================================================================
Here's the gets class


package sample2;
import java.lang.*;

public class gets {
static String str = "us";
static boolean be;
public gets() {
}

synchronized String getstr(){
while(str.equals("us")){
try {
wait();
}
catch(Exception d){}

}
be = false;
return str;
}
synchronized void setstr(){
str = "I love you";
be = true;
notifyAll();
}

}
==============================================================
the first customer class

package sample2;

public class customer1 extends Thread{
static gets gg = new gets();
public customer1() {
}
public static void main(String[] args) {
customer1 customer11 = new customer1();
customer11.start();
}
public void run(){
gg.getstr();
}

}
================================================================
Second customer class

package sample2;

public class customer2 extends Thread{
// gets gg2 = new gets();
public customer2() {
}
public static void main(String[] args) {
customer2 customer21 = new customer2();
customer21.start();

}
public void run(){
customer1.gg.setstr();
System.out.println("notifying waiting thread");
}

}
Hi everyone, did someone programming using the wait and notify methods of the object class. this is the way the class was,
there was a clas that had 2 functions, one to store a value in a string, the other to retrieve values from thesame string.
package sample2;
import java.lang.*;

public class gets {
String str;
boolean be;
public gets() {
}

synchronized String getstr(){
while(be == false){
try {
wait();
}
catch(Exception d){}

}
be = false;
return str;
}
synchronized void setstr(){
str = "I love you";
be = true;
notify();
}

}


Also wrote a class to call the retrieve method of the class above, designed it in such a way that if there is no value in the string it will wait till a value is stored
package sample2;

public class customer1 extends Thread{
gets gg = new gets();
public customer1() {
}
public static void main(String[] args) {
customer1 customer11 = new customer1();
customer11.start();
}
public void run(){
System.out.println(gg.getstr());
}

}

Wrote another class, to call the store method of the first class, after storing the value it calls the notify() method to reawaken the thread that is waiting.
package sample2;

public class customer2 extends Thread{
gets gg2 = new gets();
public customer2() {
}
public static void main(String[] args) {
customer2 customer21 = new customer2();
customer21.start();

}
public void run(){
gg2.setstr();
System.out.println("notifying waiting thread");
}

}

But I noticed that the thread I was waiting for did not reawaken and instead the thread only awoke the thrid class and not the second class.
What do you think I can do to this program
Hi everyone, did someone programming using the wait and notify methods of the object class. this is the way the class was,
there was a clas that had 2 functions, one to store a value in a string, the other to retrieve values from thesame string.
Also wrote a class to call the retrieve method of the class above, designed it in such a way that if there is no value in the string it will wait till a value is stored
Wrote another class, to call the store method of the first class, after storing the value it calls the notify() method to reawaken the thread that is waiting.
But I noticed that the thread I was waiting for did not reawaken and instead the thread only awoke the thrid class and not the second class.
What do you think I can do to this program
Hi everyone, did someone programming using the wait and notify methods of the object class. this is the way the class was,
there was a clas that had 2 functions, one to store a value in a string, the other to retrieve values from thesame string.
Also wrote a class to call the retrieve method of the class above, designed it in such a way that if there is no value in the string it will wait till a value is stored
Wrote another class, to call the store method of the first class, after storing the value it calls the notify() method to reawaken the thread that is waiting.
But I noticed that the thread I was waiting for did not reawaken and instead the thread only awoke the thrid class and not the second class.
What do you think I can do to this program
18 years ago