Hi ,
I have a piece of code which does the following by synchronizing on an arraylist. There are multiple threads which keep calling a method having the below code.
Also, the arraylistref reference keeps changing for each call.
i.e, in case we have 2 arraylist objects, arraylistobj1 and arraylistobj2.
Before executing the synchronized block of code, the arraylistref changes i.e it may refer to either one of the 2 arraylists (arraylistobj1 and arraylistobj2) during one call and the other one in the next call.
Synchronized(arraylistref){
arraylistref.add(data);
arraylistref.notifyAll();
}
P.S - There are multiple threads adding into the arraylist and also multiple threads doing remove frm the arraylist. Both are inside a synchronized block and doing a notifyall.
Occasionally I get a ,
java.lang.IllegalMonitorStateException
at java.lang.Object.notifyAll(Native Method)
Please help me why this exception occurs even though I have used a synchronized block of code. Also, a remedy to resolve this.
I have a piece of code which does the following by synchronizing on an arraylist. There are multiple threads which keep calling a method having the below code.
Also, the arraylistref reference keeps changing for each call.
i.e, in case we have 2 arraylist objects, arraylistobj1 and arraylistobj2.
Before executing the synchronized block of code, the arraylistref changes i.e it may refer to either one of the 2 arraylists (arraylistobj1 and arraylistobj2) during one call and the other one in the next call.
Synchronized(arraylistref){
arraylistref.add(data);
arraylistref.notifyAll();
}
P.S - There are multiple threads adding into the arraylist and also multiple threads doing remove frm the arraylist. Both are inside a synchronized block and doing a notifyall.
Occasionally I get a ,
java.lang.IllegalMonitorStateException
at java.lang.Object.notifyAll(Native Method)
Please help me why this exception occurs even though I have used a synchronized block of code. Also, a remedy to resolve this.