G
gast
Gast
Code:
import java.util.*;
class Listing3609 extends Thread{
private Vector v;
public Listing3609(Vector v){
this.v = v;
}
public void run(){
while(true){
synchronized( v ){
Random r = new Random();
int tmp = r.nextInt(49)+1;
v.add(tmp);
v.notify();
try{
Thread.sleep(1500);
}
catch(InterruptedException e){
e.printStackTrace();
}
}
}
}
}
class Listing3610 extends Thread{
private Vector v;
public Listing3610(Vector v){
this.v = v;
}
public void run(){
while(true){
synchronized( v ){
System.out.println("TeSt");
while(v.size() < 1){
try{
v.wait();
}
catch(InterruptedException e){
e.printStackTrace();
}
}
System.out.println("Daten empfangen: "+(Integer)v.elementAt(0));
v.removeElementAt(0);
}
}
}
}
public class Listing3608{
public static void main(String[] args){
Vector v = new Vector();
Listing3609 thread1 = new Listing3609(v);
Listing3610 thread2 = new Listing3610(v);
thread1.start(); thread2.start();
}
}
das ist mein code-fragment... ich möchte einfach das ein thread einen wert erstellt und dem anderen mitteilt das es nun weiter geht. warum funktioniert das nicht oO wo liegt mein fehler?