Piotr Gabryanczyk’s Blog

Java, Refactoring, AOP, Spring, DDD, TDD, etc.

  • Blogroll

    • I have joined Anti-IF Campaign

Synchronized – not dead yet

Posted by Piotr Gabryanczyk on May 6, 2007

Some time ago the guy I worked with started replacing all synchronized blocks with new reentrant locks (Java 5). He went to some presentation and was told that they are superior.

It looked like a weird thing to do, especially if reentrant locks had the same semantics as synchronized block.

No rush

Here is how Brian Goetz arguments no rush to replace synchronized with new locks:

“While ReentrantLock is a very impressive implementation and has some significant advantages over synchronization, I believe the rush to consider synchronization a deprecated feature to be a serious mistake. The locking classes in java.util.concurrent.lock are advanced tools for advanced users and situations. In general, you should probably stick with synchronization unless you have a specific need for one of the advanced features of Lock, or if you have demonstrated evidence (not just a mere suspicion) that synchronization in this particular situation is a scalability bottleneck.”

Advanced tools for advanced users

I also like this comment:
“Remember, these are advanced tools for advanced users. (And truly advanced users tend to prefer the simplest tools they can find until they’re convinced the simple tools are inadequate.)”

Full article here: More flexible, scalable locking in JDK 5.0

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: