fatcodeguy
Programmer
Hi,
I have several threads that are trying to access a single vector. Some threads want to add elements to the vector, others want to get elements from the vector.
I've implemented the following
The get method gets the objects from the vector (webList) and the put method adds to the vector.
It works perfectly with just one thread, and ALMOST (i hate almost) works with more than one thread. Sometimes the process finishes, sometimes it blocks.
Any suggestions?
Thanks,
I have several threads that are trying to access a single vector. Some threads want to add elements to the vector, others want to get elements from the vector.
I've implemented the following
Code:
public synchronized String get() {
if (webList.size() == 0) {
try {
wait();
} catch (InterruptedException e) { }
}
notifyAll();
return (String)webList.remove(0);
}
Code:
public synchronized void put(String fileName) {
webList.add(fileName);
}
The get method gets the objects from the vector (webList) and the put method adds to the vector.
It works perfectly with just one thread, and ALMOST (i hate almost) works with more than one thread. Sometimes the process finishes, sometimes it blocks.
Any suggestions?
Thanks,