Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronized Methods vs. java.util.concurrent API

 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Pie
Posts: 20955
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Synchronized methods
- Written by you or me

java.util.concurrent
- Written by experts
 
Carlos Morillo
Ranch Hand
Posts: 221
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Fernando,


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


Hope this helps,


Carlos.
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Fernando Franzini
Ranch Hand
Posts: 489
2
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20955
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic