This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final question : A deep thought on the criteriaFind

 
Karl Fu
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the my final question to this assignment !
I presume most of us will have a vector or other collection stuff to hold successful matches, which very likely to be initialized within the criteriaFind method.
say there are 2 user connecting to the database, both user call the criteriaFind method at the same time. When A pass in a string and he find some successful match, after he added a few successful match, his thread stops.
Client B kicks in with a different search string, initialized a new Vector....did his search....and add some record to the vector, right before he returns the matched record, he thread stops and client A continue with what he left off.
The vector initialized by B should have covered up and erased what client A had already put in the vector previously(before his thread stops), this should have lead to some display inconsistency..
However, with quite alot of testing so far..I have never come across any inconsistency with my criteriaFind method. Does it suggest that variables initialized within the method will not be affected by other threads accessing the same method ? Or is it because of other reasons ?
Any comment is appreciate !
Karl
 
Narayan Veeramani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I presume that you have the vector locally declared within
the method (not a member variable of the class). In this
case, there won't be any problem with multiple threads
accessing the criteriaFind method.
But still I am declaring this method as synchronized because
the method uses the file pointer to iterate through the database file. So if multiple threads are concurrently allowed to execute this method, the file pointer (of the member variable RandomAccessFile) may get messed up.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic