Synchronize or not synchronize the find method: that is the question.
Joined: Jan 17, 2005
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)
Joined: Mar 30, 2005
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.
author and jackaroo
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.