File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX: Physical locking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: Physical locking" Watch "NX: Physical locking" New topic
Author

NX: Physical locking

oli renard
Greenhorn

Joined: Jan 19, 2004
Posts: 28
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!)
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
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

Joined: Jan 19, 2004
Posts: 28
Thanks Satish. I have read that thread, but I am just waiting for a confirmation that this is indeed the case.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: Physical locking