• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

choice between ReadWriteLock and synchronize

 
Helen Ma
Ranch Hand
Posts: 451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Monhouse's book, in retrieveDvd(long locationInFile) method, the auther choose synchronize (database) instead of using lock.readLock().lock().
The explanation "Using a ReadWriteLock would be a counterproductive in this case, as all operations would need a WriteLock.... would result in poorer performance."

Question:
1. When I decide to use ReadWriteLock instead of synchronize keyword, should I make sure I have a thread doing writing and another thread doing reading?
2. If I only have threads doing reading from a data file, should I use synchronize keyword?
3. If I only have threads doing reading from a data file and I choose to use ReadWriteLock, the lock algorithm will end up checking if there is a write lock exist and slows down the performance. Is it true?
 
Roel De Nijs
Sheriff
Posts: 9934
113
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again: did you study the API carefully?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic