Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Locking(MaxExample and SunProject)

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic