• 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

NX: Physical locking

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone.
I have read this thread with great interest. However, I am still a bit confused regarding the synchronisation issues surrounding physical locking. I am not so concerned about record locking as I intend to have a separate LockManager to manage that. But in a nutshell, what I would have to do is this for update and delete:
a. lock the record
b. get exclusive access to the file
c. read the record
d. update/delete
e. release exclusive access to the file
f. unlock the record
and this for read and write
a. get exclusive access to the file
b. read the record
c. release exclusive access to the file
Now, since I hope to be able to use NIO, should I synchronise on a RandomAccessFile (RAF) or on the FileChannel taken from the RAF?
I do like Bahrat's solution (matching no 3 below), but effectively, I am trying to weigh up the pros and cons of 4 different approaches as I want to make an informed decision:
1) Singleton Data class with a static class variable for the RAF/FileChannel
2) Singleton Data class with a local variable for the RAF/FileChannel in each method (read, write, update, etc)
3) Non-singleton Data class with a static class variable for the RAF/FileChannel
4) Non-singleton Data class with a local variable for the RAF/FileChannel in each method (read, write, update, etc)
1) Singleton Data class with a static class variable for the RAF/FileChannel
In this case, any access to the database is synchronised on the single RAF/FileChannel instance. This seems simple enough.
2) Singleton Data class with a local variable for the RAF/FileChannel in each method (read, write, update, etc)
Now in this case, I am not sure. What should the physical locking be on? Should it be on the singleton Data class?
3) Non-singleton Data class with a static class variable for the RAF/FileChannel
Same as no 1 and seems simple enough
4) Non-singleton Data class with a local variable for the RAF/FileChannel in each method (read, write, update, etc)
This is the most difficult one. Should I add some sort of static variable in the Data class an do the physical locking on that?
In other words, what are the pros and cons of each? I am sure that each solution is viable, but since I look upon this assignment as a learning exercise, I want to make an informed decision and improve my knowledge. The best way to do this is to be aware of the pros and cons of each approach. Any help would be very much appreciated as I am not that knowledgeable about threading and no very little about RMI - i really have my work cut out!
Thank you
oli renard - un p'tit belge de Liege (mais qui habite en GB!)
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi oli renard,
I think we are not supposed to use the NIO packages for the projects. Check it out here
So if NIO is restricted, we cannot use FileChannels right. Hope this helps, thanks.
 
oli renard
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Satish. I have read that thread, but I am just waiting for a confirmation that this is indeed the case.
 
reply
    Bookmark Topic Watch Topic
  • New Topic