• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt about Locking in URLyBird 1.1.2

 
rohan tiwari
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the DB interface provided by Sun, only the update,delete,lock and unlock methods throw RecordNotFoundException and SecurityException.

The create,read and find methods do not throw these exceptions.
So, Can I implement locking in these 3 methods just by synchronizing on the RandomAccessFile object?Is it allowed?

Please reply
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did the B&S assignment, from the posts an option is to synchronize the create() since there is a possibility that 2 clients will try to write at the same location.
read() also requires locking to make sure that the read record is not being changed.
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi;

also i think any method will use RandomAccessFile object must be synchronize , also i synchronized the part when i read the length of the file. but i think when the find method use read method it may be not necessary to synchronized it because the read method is synchronized.

BR;
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed,

You synchronize the reading and writing part of the method when you access the RandomAccessFile. Another alternative would be opening the file in aech and every method that needs to access the file, that way you don't need to synchronize plus you can close the file when you are done.
 
rohan tiwari
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing,

Before deleting a record I call the lock method and get a cookie value.I use this cookie value while deleting the record.After deleting , should I call unlock, because if I do the record is deleted and there would be a RecordNotFoundException.
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi rohan tiwari;

also the record deleted but the cookie value still in the lock manager so
you must unlock the record but for RecordNotFoundException you can check
the existing of the recrod if the record is deleted then first delete the cookie then throw the exception, or you can treat the exception as treating the DuplicateKeyException don't forget to write this in Choices
document.

hi Musab Al-Rawi;

do you know the number of threads that will use your application and
do you know the number of allowable open files the OS allowed to open.

BR;
 
rohan tiwari
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that resolves the issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic