[concurrency-interest] Is it still ok to use synchronized after all these years?

Yao Qi qiyaoltc at gmail.com
Fri Nov 12 21:19:17 EST 2010

On Sat, Nov 13, 2010 at 5:43 AM, Ashwin Jayaprakash
<ashwin.jayaprakash at gmail.com> wrote:
> I was wondering if it is still ok to use the "synchronized" keyword instead
> of ReentrantLock where it is convenient.

Yes, of course.

> Or is it thought of as an anachronism?


> Does synchronized still have a better internal implementation over
> j.u.c.Lock as this old blog entry says -
> http://blogs.sun.com/dave/entry/java_util_concurrent_reentrantlock_vs ?

The choice between "synchronized" and j.u.c.Lock depends on your application
or workload.  If your application is a heavy concurrent code, and suffered by
lock contention, you could try j.u.c.Lock, otherwise, "synchronize" is
still pretty
good if you are aware of the scope of it.

> Thanks,
> Ashwin Jayaprakash.
> PS: Doug Lea - if you are reading this, I hope you will continue to make
> your awesome contributions to the JDK! I can't imagine what it would be like
> without the j.u.c code.

Yao Qi <qiyaoltc AT gmail DOT com>

More information about the Concurrency-interest mailing list