This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

The find method in the Data class

 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, everyone

I use the cache to store all records which are read from the database file
when the program starts, so the find method in Data class will search relative records in an ArrayList object to find which exactly match the user's criteria. I think the find method is needless to use the sychronized modifier, right?

Thanks in advance!
Regards, Ailsa Cape
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Posts: 12056
232
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ailsa,

Well you probably don't need to synchronize the entire method, but you might still want to ensure that you are not retrieving a record from the collection at the same time that any other client is modifying the collection. So synchronization somewhere might still be in order.

Regards, Andrew
 
Ailsa Cape
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Andrew

Thanks a million!

I think I fully understand your meaning and I must use the synchronized modifier from within the find method to prevent others modifying the collection simultaneously.

Best Regards, Ailsa Cape
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!