[concurrency-interest] Is it still ok to use synchronized after all these years?
tim at peierls.net
Fri Nov 12 16:56:56 EST 2010
On Fri, Nov 12, 2010 at 4:43 PM, 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.
The main reason to use Lock is for these capabilities:
- Non-nested locking
- Lock.tryLock (timed/untimed)
If you don't need any of these, go ahead and use 'synchronized'.
> Or is it thought of as an anachronism?
Nope. It's much easier to read, and there's no danger of forgetting to
release the lock.
> 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 scales have shifted back and forth, but it's not something to worry
about at this point.
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.
I'm sure Doug _is_ reading this!
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Concurrency-interest