DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: Synchronized

Hybrid View

  1. #1
    Join Date
    Apr 2005
    Posts
    2

    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

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links