Hi all,
Please help explain the following program.
Why it might cause a deadlock? And how to fix it?
Thx in advance.
With multiple threads calling create() and remove() we are getting a
Java deadlock, how would you fix ?
class A{
public static Object create(){
Object obj = new Object();
synchronized( list){
list.add( obj);
callCount();
}
return obj;
}
public synchronized static void remove(Object obj){
synchronized( list){
list.remove( obj);
callCount();
}
}
public static synchronized int callCount(){
return count++;
}
private static int count;
private static ArrayList list = new ArrayList();
}