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
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.
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!