J
John_Woo
Hi,
I want some classification on understanding the context of synchronized
reference:
say
LinkedList queue = new LinkedList();
public Object pop() throws InterruptedException {
synchronized(queue) {
while (queue.isEmpty()) {
queue.wait();
}
return queue.removeFirst();
}
}
public void put(Object o){queue.add(o);}
public void do(){
pup();
put(o);
put(o);
pup();
..
}
case 1
op never called
case 2: pop called only once
cass 3: pop/put called many times
I'm wondering, in above 3 cases, what happened to queue in terms of
synchronization?
like,
in case 1, is it queue not synchronized?
in case 2, if queue size always > 0 ; queue not synchronized?
when queue is synchronized in pop, did that imply it synchronized
anywhere in same class?
I want some classification on understanding the context of synchronized
reference:
say
LinkedList queue = new LinkedList();
public Object pop() throws InterruptedException {
synchronized(queue) {
while (queue.isEmpty()) {
queue.wait();
}
return queue.removeFirst();
}
}
public void put(Object o){queue.add(o);}
public void do(){
pup();
put(o);
put(o);
pup();
..
}
case 1
case 2: pop called only once
cass 3: pop/put called many times
I'm wondering, in above 3 cases, what happened to queue in terms of
synchronization?
like,
in case 1, is it queue not synchronized?
in case 2, if queue size always > 0 ; queue not synchronized?
when queue is synchronized in pop, did that imply it synchronized
anywhere in same class?