aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Synchronized Methods vs. java.util.concurrent API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Synchronized Methods vs. java.util.concurrent API" Watch "Synchronized Methods vs. java.util.concurrent API" New topic
Author

Synchronized Methods vs. java.util.concurrent API

Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Hi Folks

In SCJD we have 2 lock solution to choose: Synchronized Methods and java.util.concurrent API.
Could you raise with me some advantages and disadvantages of each ?

Synchronized Methods
-Easy implemention.
-slowly (exclusive lock).
-No guarantiees about next granted thread.

java.util.concurrent
- complicated implementation
- faster (read/write lock).
- Guarantiees about next granted thread.

What else ?

Regards.

Fernando Franzini - Java Blog
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18898
    
    8

Synchronized methods
- Written by you or me

java.util.concurrent
- Written by experts
Carlos Morillo
Ranch Hand

Joined: Jun 06, 2009
Posts: 221

Hi Fernando,


I'd suggest you get a copy of this book.


Hope this helps,


Carlos.


SCSA, OCA, SCJP 5.0, SCJD, CCDH, CCAH http://www.linkedin.com/in/carlosamorillo
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
The performance of synchronization has actually become a whole lot better with Java 5 and 6, up to the point where there's practically no slowdown in the case of an uncontested lock.

I disagree that the java.util.concurrent package is only for experts (or maybe our definitions of "expert" are different :-). It's non-trivial stuff, to be sure, and you need to know what you're doing, but there's some very useful stuff in there, like ReentrantReadWriteLock and Executor and friends.

If you're at all serious about multi-threaded Java programming -and who isn't these days?-, I advise to read one of the eminent books (either Goetz or Oaks/Wong).


Ping & DNS - my free Android networking tools app
Fernando Franzini
Ranch Hand

Joined: Jan 09, 2009
Posts: 486
    
    2

Sorry but I dont have time to read and deliver my assignment.
The goal of this post is each ranchers add rapid text of advantages and disadvantages.
Thanks anyway.
Regards.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18898
    
    8

Ulf Dittmer wrote:I disagree that the java.util.concurrent package is only for experts...


I do too. What I meant was that it was written by experts and hence more likely to work correctly than code written by non-experts, but apparently that came out the wrong way around.
 
Consider Paul's rocket mass heater.
 
subject: Synchronized Methods vs. java.util.concurrent API