File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes need your help :new synchronized problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "need your help :new synchronized problem" Watch "need your help :new synchronized problem" New topic
Author

need your help :new synchronized problem

LianGuang Wang
Greenhorn

Joined: Mar 26, 2006
Posts: 11
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 ]
Josephx Rainerd
Greenhorn

Joined: Apr 27, 2006
Posts: 12
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

Joined: Mar 26, 2006
Posts: 11
thank you Josephx
I read your post but i didn't get your meanings. Could you please be more detailed?
Jar Jaquiso
Greenhorn

Joined: Apr 20, 2006
Posts: 26
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

Joined: Mar 26, 2006
Posts: 11
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!
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
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.


42
LianGuang Wang
Greenhorn

Joined: Mar 26, 2006
Posts: 11
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.
Roy Mallard
Ranch Hand

Joined: Jul 14, 2005
Posts: 53
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.


SCJP 1.4<br />SCJD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need your help :new synchronized problem
 
Similar Threads
name and/or location search
GUI Search Question
find method signature and synchronized.
Conflicting search requirements (URLyBird 1.1.3)
Exactly match searching in URLYBird