Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it convenient that I use the finalize() of the session facade to release its locks

 
Hu Yong Jun
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In DB interface, the method lock() take the form as public long lock(int recNo). I think the return value of long type is the lock cookie(lockCookie).

The session facade holds the lock cookies standing for the record locks created by itself. On the other hand, the signleton object of LockManger holds all the lockCookie/recordLock pairs and is shared by all clients.

How can I know which lockCookie/recordLock pairs in LockManage belong to a session facade when the session facade dies? I want to release the locks belonging to the dead session facade.

Is it convenient and feasible that I use the finalize() of the session facade to release its locks before boing collected?

This problem can be resolved that the LockManager holds the weak references to lockCookie of Long type if I could change the return type from long to the wrapper Long object in lock() method.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hu Yong Jun,

finalize() is called when there are no more references to your object. So as long as the remote client is the only class that has a reference to your object then you can use the finalize() method to clear up your locks.

If there is any chance that some other (local) class has a reference to your object, then finalize() wont be called. In this case you might want to look at using the java.rmi.server.Unreferenced interface, which will be called when there are no more remote references to your object.

Either way can work.

Regards, Andrew
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hu Yong Jun,

You might also be interested in looking at the discussion Peter and I are having in this thread. I mention some of the issues with unreferenced() and finalize() in there.

Regards, Andrew
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic