• 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

need your help :new synchronized problem

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
it's mentionned in my exam:
"the user interface must allow the user to search the data for all records, or for records where the name/or location fields exactly match value specified by the user"
Question 1:
so the method should like this
1: int[] a = find (String[] criteria)
2: for(........) {
3: String[] b = read(int recNo);
4: }
OK! between step 1 and step 3,other clients perhaps change the value! so the result will be error! how can i deal with this situation? only synchrnized this method will not be helpful.


To further divorce the concept between performing a search and displaying data, the search method does not return records - it returns record numbers. You have to retrieve the records based on the numbers in a separate step. So you would presumably be validating that the records still matched anyway (otherwise the records could change between when you complete the search and when you retrieve the record).


It is also helpful to do a complete search because there is a possibility you could get wrong records with the partial search. Consider the following:

1) You find() a bunch of matching records.
2) You read() each record.

But multi-threading, that record could have been changed between the find() and read(), and even though it matched at the time of the find(), it does not match at the time of the read(). How to catch it? With the conveniently required complete search. So come to think of it, the requirements would be incomplete were they not dual this way.



above statements are about the same question that i have mentioned ,who can give some indications.
thanks

[ May 02, 2006: Message edited by: LianGuang Wang ]

[ Nope - not urgent!]
[ May 02, 2006: Message edited by: Barry Gaunt ]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question1 :
What about allowing the data be Out of sync (corrupted) and doing the checks while writing the data back only ?
You can guarantee concurrency by synchronization ( not necesaarily the find method) , but can not be certain your data is not stale while you are displaying it.


Question2:
I return booked records also.

Thanks
[ May 01, 2006: Message edited by: Josephx Rainerd ]
 
LianGuang Wang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you Josephx
I read your post but i didn't get your meanings. Could you please be more detailed?
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've resolved this by re-validating each record as I read it:

1: int[] a = find (String[] criteria)
2: for(........) {
3: String[] b = read(int recNo);
4: if validate(b, criteria) {
5: // use record
6: }
7: else {
8: // discard record
9: }
10: }

This way you can also do an "exact-match" comparison, as the DBAccess interface states that the comparison is a "starts-with" comparison.
 
LianGuang Wang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Jar Jaquiso
i Understand what you mean,through two compare to confirm results.it's good!
these like dirty read or no repeat read in database.
can we extend the Data object ,and add a new method synchronized on RAF to do the same job? under this situation,two steps would be atomic!
who can provide me with further confirmation?
thanks!
 
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You always run the risk of the data that one client sees is out of synch with the database at the time he sees it, unless you lock all records on read and don't allow reading locked records.
But if you do that you'd not be able to connect several clients as all but the first would initially get an empty dataset, less than useful.
 
LianGuang Wang
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Jeroen T Wenting
you are right!My approach is not a wise choice!Exclude this option.i will follow Jar Jaquiso's way!
thanks.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can identify out of date records by using timestamps.
For example, the client gets a timestamp for each record returned in the search. When the client tries to book a record, the server checks to make sure the client's timestamp for the record is not older than the record's timestamp on the server.
Hope that helps.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic