Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!

Josephx Rainerd

Greenhorn
+ Follow
since Apr 27, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Josephx Rainerd

Hello

My B&S assignment datafile, has values padded with space though ,mentioned in spec, that length < max length needs to be null terminated.


I (so far) took the approach of padding with spaces)(ignoring spec and documenting the reason).

In my search screen, I return
'Fred' matches 'Freddy'
'Fred' DOES NOT match 'Freddy' for exact search
BUT 'Fred' matches 'Fred ' space padded for exact search

I do not see any way of distinguishing 'Fred' and 'Fred ' .

Is that going to upset Sun?

Also I let empty field (unless exact search) match all data. So all blank fields, in effect return all records.( I have a GUI element in screen) to chose 'Show all' also ).

Thanks
I downloaded my assignment 6 months back. I coded as per jdk1.4.
Do I need to do ANYTHING other than making sure it compiles and without warning with jdk1.5 and runs?

Thanks


Object synch = locks.get(recordId); if (synch == null) { synch = locks; } synchronized (synch) { while (locks.containsKey(recordId)) { synch.wait(); } locks.put(recordId, cookie);



Regarding synchronizing, consider :
Assume a Thread1 gets, synch = locks.get(recordId) returns valid reference.


Before this Thread1 hits synchronized (synch) {..} block, the owner thread (Thread2) of that record deletes the record. Thread1 is unaware of that and locks on the stale reference and proceeds. That breaks the locking model.

[ May 10, 2006: Message edited by: Josephx Rainerd ]
[ May 10, 2006: Message edited by: Josephx Rainerd ]

Object synch = locks.get(recordId); if (synch == null) { synch = locks; } synchronized (synch) { while (locks.containsKey(recordId)) { synch.wait(); } locks.put(recordId, cookie);// further code



Not sure if the its typo, seems the check if (synch == null) is not done in sync-ed context and might not fulfill the purpose.

I check if record is active before going into and after waking up from wait state. And the baby waits and wakes up in sync context obviously.

Thanks
[ May 10, 2006: Message edited by: Josephx Rainerd ]
Are you not using the methods in a synchronized context ??

If so, what are you synchronizing on?

created a separate Lock class that will hold the record number and the cookie. I synchronize on this lock object.



Since you are locking on 'Lock' object , which holds record number and the cookie, why do you need LockManager to be singleton?

For example,

//A sigleton class
class Lock {
Collection someCollection < recordNo, cookie>
}

You can happily lock a record by adding an entry to the someCollection after obtaining lock on the single instance of Lock object.
Yes, the collection would contain <recordNo, cookie> for all locked records in the system.

Hope it makes sense.
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 ]
Hi

I was wondering if it makes sense to validate parameters in the Table (or TableModel) itself. Since Table comes with editors, some sanity checks can be automatically taken care of.(Sun wants JTable!)
It Table OK's the data, it makes to the database, no more checks.

Thanks

Synchronization now i have changed and created a separate Lock class that will hold the record number and the cookie. I synchronize on this lock object.



What if you make ONLY the Lock class singleton and let the rest have multiple instances ? You would be controlling the concurrency from one point towards the end of the flow. Its just a suggestion ...
I am no expert in design..
Jeroen

Thanks for replying. Your design is good.

I am just curious.., as I understand, you have a connection factory to create either local or remote connection.Local connection uses local data access methods and remote connection uses remote data access methods(which are similar, but coded separately).
The Connection class (returned by factory) still wraps both Local and Remote data access classes.
If a data access enhancement is needed, it needs to be done in both the data access implementations.

Thanks

If one person is writing rec 1 then till he does so no one will be able to write to any other record since he will have the lock for hte DBReader instance.



Are you synchronizing on the write method of DBFileHandler?
I do not know if the URLyBird assignment requires to have a decoupled lockRecord(recNo) ... (B&S assignment does..).

If you use a pool of DBFileHandler, what do you synchronize on to maintain data integrity?
#1 #2 #3
Your control flow is : DBManager => DBFileHandler => actual data

and you might be maintaining data integrity by controlling #1 AND #2 (Even singleton DBManager will be shared by multiple RMI threads concurrently).
Is it better to control the data integrity in one place, possible towards the end of the control flow?

Gist is, what would you gain by making DBManager singleton?

Thanks
Well , I am reposting after correction.
=============================================


I do appreciate opinion on the following:

My assignmentis B&S. I modelled the server class(RMI and standalone) as

// Parent interface
public interface Server {
public String[] read(long recNo) throws Exception;
..
}

// RMI client
public interface RemoteServer extends Remote,Server {
public String[] read(long recNo)
throws RemoteException,RecordNotFoundException;
...
}

// Standalone server
public class StandAloneServer implements Server {
public String[] read(long recNo) throws RecordNotFoundException { .. }
....
}

So I do ...
Server server = new StandAloneServer (port etc..) ..
or
Server server = Naming.lookup(name etc..) ..

#2
My Database design uses Adapter pattern and does not care if it is Remote or stand alone server.

Thanks
-Joseph
[ April 28, 2006: Message edited by: Josephx Rainerd ]