• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Locking(MaxExample and SunProject)

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic