Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronize or not synchronize the find method: that is the question.

 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

Reading some topics I saw that some people have synchronized their find method in Data class. But I am not sure why and do I need to do this?
How do you think, should the find method be synchronized?

Can you help me?
Thanks a lot!
Olena
 
Uriy Kashtanoff
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Olena,

My find method is not synchronized. If you have designed your Data class without find being synchronized, then you shouldn't worry about somebody else's decision and second guess yourself.

If find is synchronized, then this implies that only one thread at a time can be running it. Is that the behavior you want? I personally allow mutliple threads into the find, and only down deep within the find implementation (actually, another class that does record managing), when it comes to reading the file (via classes in java.io package) do I synchronize.

Hope this helps.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11945
212
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Olena,

I think the logic behind synchronizing the find method, is that doing so means that records cannot have been added/deleted/modified while the find method is running.

My personal opinion is that this is unnecessary - all the find method returns is a set of record numbers, so the records could be added/deleted/modified between when the find method returns and when the records are read. So you are not really saving yourself anything.

Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic