-
Synchronized
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
-
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks