Hi,
I got a question about synchronized. I got a threaded application and I want to lock an array to be shore I'm not trying to update it while using it.
Here is what I do:
public void a() {
synchronized (array) {
//do some stuff
}
}
public void b(Array newArray) {
array = newArray;
}
Does this protect me from not updating the array from function b while using it in function a or do I have to do something more, maybe synchronize function b?
Thanks!
Erik
04-25-2005, 08:02 AM
sjalle
I think what you need to do is make synchronized accessor functions for the array.
What you are doing above is strictly speaking not an update of the array but
a reallocation. If there is an (unwanted) possibility that this can occur
(reallocation during update/access) you should enclose the array data in a class and
implement a singleton in that class + synchronized setter-methods.