This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Locking(MaxExample and SunProject) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Locking(MaxExample and SunProject)" Watch "Locking(MaxExample and SunProject)" New topic
Author

Locking(MaxExample and SunProject)

Peter Kovgan
Ranch Hand

Joined: Sep 18, 2003
Posts: 84
Hi guys!
Please, help me! Sorry for my English.
This is my view of problem and my question:
1)Max's book example has DVDDbAdapter class to lock .DVD file before process any operation with this file.
Lock file in this example means : dont allow 2-d access to this file while some client access(locked) it.
Each record saved in different file so lock record means lock file.
Only find operation don't demand locking.
Static vector consists off UPC numbers(locked files names)to synchronize access from different clients and from different methods of any one client.
So system works like this:
StartAnyMethodOfAnyClient->takeLockOnWholeFile->DoJob->rleaveLock->endMethod
Using RMI don't change anything, cause every method call must take file lock.
Is this all right?
2) Sun's Contractors project has only 1 DB file, so this is some different situation...All records within one file...
Suppouse I use one Instance OF RandomAccessFile(RAF) for every client, so when client connect to DB he create RAF instance(Need I synchronize it, make static?). When I use RMI even one client can access this instance from 2 threads, even during one method invocation. So I MUST(?question) lock DB file for every method invocation of every client as we did in Max's example?And releave lock at the methods exit?
Or it's possible to lock only some record in the file?
Please, help me , I need any idea.
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Peter,
1) (...) Is this all right?

Yes.
2) Sun's Contractors project has only 1 DB file, so this is some different situation...All records within one file...
Suppouse I use one Instance OF RandomAccessFile(RAF) for every client, so when client connect to DB he create RAF instance(Need I synchronize it, make static?). When I use RMI even one client can access this instance from 2 threads, even during one method invocation. So I MUST(?question) lock DB file for every method invocation of every client as we did in Max's example?And releave lock at the methods exit?
Or it's possible to lock only some record in the file?

We must implement "logical" record locking, meaning no file locking and no record locking at the physical level. If you synchronize on some static RAF (or on any other shared monitor you set up), it will be for other purposes than locking (to avoid dirty reads for example). Depending on your design (NIO vs IO, single Data instance vs multiple instances, ...), there are multiple valid ways to do it. By doing a search on this forum, you should get many of them.
Best,
Phil.
 
Don't get me started about those stupid light bulbs.
 
subject: Locking(MaxExample and SunProject)
 
Similar Threads
single raf vs. raf per client
Design 01
More on locking
Fantastic!! My RMI surprised me!!! :confused:
B&S Locking Strategy