wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Synchronize or not synchronize the find method: that is the question. 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 "Synchronize or not synchronize the find method: that is the question." Watch "Synchronize or not synchronize the find method: that is the question." New topic
Author

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

Olena Golub
Ranch Hand

Joined: Jan 17, 2005
Posts: 113
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


SCJP 1.4<br />SCJD 1.4 (in progress)
Uriy Kashtanoff
Greenhorn

Joined: Mar 30, 2005
Posts: 7
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

Joined: Mar 28, 2003
Posts: 11432
    
  85

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


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Synchronize or not synchronize the find method: that is the question.