J
jimjim
Hi there,
Considering multiple concurent threads producing - consuming Objects
from the Vector by calling the send() and receive() functions of the
MessageQueue (see below), is a race condition possible? (as there are no
shared data/variables) That is, what may happen if a thread invokes send( )
and be switched with another thread that starts consuming with receive( ) ?
Is there a possibility that sth will break?
Responsible answers please. Do be verbose.
Thank you in advance.
jimijm
public class MessageQueue {
private Vector queue;
public MessageQueue() {
queue = new Vector();
}
public void send(Object item) {
queue.addElement(item);
}
public Object receive() {
Object item;
if (queue.size() == 0)
return null;
else {
item = queue.firstElement();
queue.removeElementAt(0);
return item;
}
}
}
Considering multiple concurent threads producing - consuming Objects
from the Vector by calling the send() and receive() functions of the
MessageQueue (see below), is a race condition possible? (as there are no
shared data/variables) That is, what may happen if a thread invokes send( )
and be switched with another thread that starts consuming with receive( ) ?
Is there a possibility that sth will break?
Responsible answers please. Do be verbose.
Thank you in advance.
jimijm
public class MessageQueue {
private Vector queue;
public MessageQueue() {
queue = new Vector();
}
public void send(Object item) {
queue.addElement(item);
}
public Object receive() {
Object item;
if (queue.size() == 0)
return null;
else {
item = queue.firstElement();
queue.removeElementAt(0);
return item;
}
}
}