This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a couple of questions for experienced programmers(and for SCJD guru). My db server ("Contractors" project) has such architecture: every client has Data object, this object responsible for 1)records locking/unlocking in methods lock(), unlock() 2)reading, updating...in methods read(), update()... Important: All Data objects share singleton constructed object DataFileHandler responsible for reading/writing from/in RAF. Record locking methods of Data:lock/unlock sinchronized on some List of locks, but read/update methods of Data synchronized on DataFileHandler(and here is a question!!!) My fat client calls lock()(synchronized on List locks), then calls read()(synchronized on DataFileHandler), then unlock()(synchronized on List locks):
My question : is it good(or allowed) solution to sinchrnize some methods as lock()/unlock() on List locks, but read()/update() synchronize on DataFileHandler(on single instance of RAF)? I see here record locking and file locking together. Please, give me some advise or another way to think better.
Originally posted by Peter Kovgan: is it good(or allowed) solution to sinchrnize some methods as lock()/unlock() on List locks, but read()/update() synchronize on DataFileHandler(on single instance of RAF)?
Hi Peter, I can't vouch for how good that design is but i can definitely say it's allowed since the specs don't disallow any particular locking implementation (and furthermore, my implementation is similar to your design and it works ). Just be sure you aren't nesting locks, or else you'll have to account for deadlock scenarios. I have tested this design by simulating 30+ clients connecting to my server and updating the same record, while simultaneously spawning a client of my own to update different record(s), and i haven't run into any data consistency problems (yet? ).
Sun Certified Java Web Component Developer for J2EE v1.4<br />Sun Certified Java Developer for J2SE v1.4<br />Sun Certified Java Programmer for J2SE v1.4
Joined: Sep 18, 2003
Hi Paul! Thank you very much for your reply. I think this solution is allowed,but I still in doubt regarding to possible scenarios with IO. Suppouse I call record locking, then stating reading file, but my reading failed and IO call does not return(some problem with file reading, but without exception)from method. I think about possible solutions for the problem, like some monitor thread, checking time out of the IO response. Do you have some experience in the situation, or you prefer "good documented but not resolved problem" solution in the case? Thank you. Peter.
Joined: Sep 30, 2003
Originally posted by Peter Kovgan: ... Suppouse I call record locking, then stating reading file, but my reading failed and IO call does not return(some problem with file reading, but without exception)from method.. Do you have some experience in the situation, or you prefer "good documented but not resolved problem" solution in the case?
Hi Peter-- I do not have any experience with IO errors that do not throw exceptions-- and I imagine I would despise them immensely if I did . In the following scenario: db.lock(recNo) --> db.read(recNo) --> ERROR (that throws IOException) I unlock the record in my catch clause. However, I have yet to handle exceptions thrown by my lock/unlock functions and I wonder if this is necessary? Although this "design hole" can be left to our choices documents, I'd definitely like to hear anyone's opinion on how they handled errors in these cases. Sorry I couldn't be of more help Peter.