Thank You for traing to help me.I solve my problem.
Here is the code:
class km1Monitor extends Object {
private int take_place = 0;
private int nmb_wolf=0;
private int br_misionara=0;
synchronized public void insertwolf() {
while (take_place==3 || (br_misionara==1& nmb_wolf==1)){
try{
wait();
} catch (InterruptedException ex) {};
}
take_place++;
nmb_wolf++;
System.out.println("Enters wolf.");
if(take_place==3){take_place=0; nmb_wolf=0;nmb_sheap=0;System.out.println("Transport anb back with empty boat i");notify();}
}
synchronized public void insertsheap() {
while (take_place==3 &nmb_wolf==2) {
try{
wait();
} catch (InterruptedException ex) {};
}
take_place++;
nmb_sheap++;
System.out.println("Enters sheap.");
if(take_place==3){take_place=0; nmb_wolf=0;nmb_sheap=0;System.out.println("Transport and back with empty boat");notify();}
}
}
public class km1 extends Thread {
private km1Monitor theMonitor=new km1Monitor();;
private class Wolf extends Thread {
public void run() {
while(true) {
System.out.println("Wolf is trying to enter");
theMonitor.insertwolf();
try {
sleep(100);
}
catch (InterruptedException ex){}
}
}
}
private class Sheap extends Thread {
public void run() {
while(true) {
System.out.println("Sheap is trying to enter");
theMonitor.insertsheap();
try {
sleep(100);
}
catch (InterruptedException ex){}
}
}
}
public void run(){
Wolf aWolf=new Wolf();
Sheap aSheap=new Sheap();
aSheap.start();
aWolf.start();
while(true) {}
}
public static void main(
String args[]) {
km1 holder = new km1();
holder.start();
}
}
Problem was in main method but i'm relativly new in java so these mistakes could happen.
with regardes
Michael