Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

synchronized

 
Jim DiCesare
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The interface I was given doesn't use synchronized functions, so should I:
make all my file accessing functions synchronized
or
add a synchronized block around all file access'
 
George Marinkovich
Ranch Hand
Posts: 619
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No interface can contain synchronized as it is an implementation detail.
So, yes the Data class members implementing the DBMain interface may be synchronized.
Alternatively, the code manipulating the database file could be placed within a synchronized block (maybe synchronized on the file).
I think it's easier to synchronize the methods, but that's just my opinion.
This is a good thread to look at (especially Andrew's post at the end):
Topic: lock/unlock & synchronized
Hope this helps,
George
[ January 09, 2004: Message edited by: George Marinkovich ]
 
Jim DiCesare
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah, I think I'll just synchronize the methods. It gets difficult to think of all the possible places where one thread might stop, and another might come in and mess things up.
I just thought it might be a little slow to synchronize all the methods, and I might get points off for losing efficiency by not synchronizing as little as possible while maintaining thread safety.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic