Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Final question : A deep thought on the criteriaFind

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 !
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.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic