Say I have something like this (and I do)
class QueBean extends JPanel {
private Queue queue = new LinkedBlockingQueue();
public Object poll(){
return queue.poll();
}
}
with some of these that run on their own threads
class ConsumerBean extends JPanel implements Runnable{
private QueBean queBean;
public synchronized run(){
while (true) {
Object result = queBean.poll();
if (result != null) {
jResultTextField.setText("got one");
}
wait(500);
}
}
}
Should my poll()
in the QueBean
be synchronized
or not?