java.lang.IllegalMonitorStateException: current thread not owner
HI!
N00b need help =)
Its an producer consumer thread program that is surpouse to me synchronized.
Here is what I thougt would be the way:
publicclass Ringenimplements Buffer
{
privatestaticfinalint BUFFER_SIZE = 10;
int in, out;// peker p?f鴕ste ledige og siste okuperte.
int count;// Teller hvor mange objekter som er i bufferen.
private Object[] buffer;
public Ringen()
{
count = 0;
in = 0;
out = 0;
buffer =new Object[BUFFER_SIZE];
}
publicvoid insert(Object item)
{
while (count == BUFFER_SIZE){
try{
wait();// If buffer is full put thread on waitinglist
}//end try
catch(InterruptedException e){
System.out.println("ERERERR"+e);
}
}//end while
// Legger til et object i bufferen
++count;
buffer[in] = item;
in = (in + 1)% BUFFER_SIZE;
}
public Object remove()
{
Object item;
while (count == 0){
try{
wait();
}//end try
catch(InterruptedException e){
System.out.println("ewwerwerwe"+e);
}
}//end while
--count;
item = buffer[out];
out = (out + 1) % BUFFER_SIZE;
return item;
}
}
**********************************************************************************
import java.util.Random;
publicclass Generateextends Thread
{
private Random genr =new Random();
private String[] liste =new String[10];
private Ringen buffer;
privateint nr;
public Generate(Ringen ring)
{
buffer = ring;
liste[0] ="Iron Maiden";
liste[1] ="Killers";
liste[2] ="The Number Of The Beast";
liste[3] ="Piece Of Mind";
liste[4] ="Powerslave";
liste[5] ="Life After Death";
liste[6] ="Somewhere In Time";
liste[7] ="Seventh Son Of The Seventh Son";
liste[8] ="No Prayer For The Dying";
liste[9] ="Fear Of The Dark";
}
publicvoid run()
{
while(true){
nr = genr.nextInt(10);
buffer.insert(liste[nr]);
}//end while
}
}
]
That is the buffer and one of the producers...
When I run it this error message comes up:
java.lang.IllegalMonitorStateException: current thread not owner.
everytime eithera producer or consumer cals one of the two methods in Ringen I get one of those on the method call...
So... please help :)

