• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic