|
![]() |
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
You may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple concurrent clients of your server.
2. The scenario you describe is right. But it's not the reason for which I advice you to not bypass the locking scheme in stand-alone mode (it wouldn't help anyway as it doesn't span multiple JVMs). You should have something like this in your instructions :
quote:
--------------------------------------------------------------------------------
You may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple concurrent clients of your server.
--------------------------------------------------------------------------------
As the server and the stand-alone client are two different programs, don't care about possible conflicts
Are there any other reasons for not bypassing the locking protocol in "alone" mode apart from rendering it easier for later "network" mode development?
Derek:
In this case (Phil: data is singleton and read/write methods are synchronized), do i still need to enforce the lock/update/unlock contract?
Michael:
If the methods are synchronized, and they need to be because even if you sync a block inside the read / write methods, another thread could change the parameters before the first thread finishes it's processing, so you need to sync the whole method.
Michael:
Of course if the interface wasn't so ugly, you could then in fact implement a locking at the record level, which would be elegant and more efficient.
I must disagree. Methods parameters are put on the stack (same as a local variable). So no other thread has access to them.
If an io exception is thrown inside a write method, the data could be partially written, i.e. corrupt, is it necessary to have a rollback mechanism? The answer to this is going to make or completely ruin my day.
I was just about to sift through the rollback code in MySql to have a look at what they did.
[Michael]: I think I have a solution for my previous doubt. The only way that the locking mechanism could be beneficial is by NOT implementing the singleton model in Data, the locking table, or vector, whichever you use must be static and in the event of multiple Data instance.
A clear design, such as will be readily understood by junior programmers, will be preferred to a complex one, even if the complex one is a little more efficient.
[Phil]: The real question is : do you really *need* to synchronize read/write methods as a whole ?
it's a contract ... and a contract (the interface) *must be* fulfilled
[Michael]: So if you are syncronizing all the methods, like myself
[Phil]: The real question is : do you really *need* to synchronize read/write methods as a whole?
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
|