Synchronized


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Synchronized

  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.

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center