This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Performance and the fly likes Synchronized block Vs Concurrent Lock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Synchronized block Vs Concurrent Lock" Watch "Synchronized block Vs Concurrent Lock" New topic
Author

Synchronized block Vs Concurrent Lock

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1371
Which gives best performance Synchronized block / Concurrent Lock ?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7519
    
  18

kri shan wrote:Which gives best performance Synchronized block / Concurrent Lock ?

In theory, the latter is supposed to be more scalable, and does allow a bit more flexibility; but it comes at the expense of more code and thus more chances for "getting it wrong" and/or making things less readable.

Unless you're actually writing a critical multi-tasking system, I'd suggest you only use the latter if you can prove that it makes sense. And that means LOTS of testing of both forms.

Winston
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Synchronized block Vs Concurrent Lock
 
Similar Threads
synchronized
synchronized and ReentrantReadWriteLock
Synchronized method and Sychronized block
exception in sync block
Synchronizing Code