이희승 (Trustin Lee) wrote:
On Thu, 15 May 2008 16:47:32 +0900, Emmanuel Lecharny <[EMAIL PROTECTED]> wrote:

이희승 (Trustin Lee) wrote:

The problem is we have so many properties which needs visibility independent from each other.
Do we have a list of all the properties we need to protect? This could be a good start to discuss about the best mechanism to use to protect them.
If we are going to use a lock, we will need as many lock objects as the number of the properties, which is way too much IMO.
You can also synchronize the get() and set() methods, and you don't need a lock anymore. Actually, this might be even more performant than using volatile, if the property is read many times.

using synchronized modifier for a method is same with synchronized (this) {...}, and it means all properties of one object will share one single lock and cause serious contention.

Fair enough. In this case, in order to protect the property, AtomicXXX is the best solution for simple types (what a burden to create a lock to protect an int or a long ... !). If we have access to imutable data (like String), we don't care about synchronization, as the data are immutable. For any other data structure, we can do a synchronize(data) inside the get() and set() (and any other methods), so no need to use a dedicated lock.

--
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org


Reply via email to