This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locking issues

 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11945
212
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Surya,

You can use the java.rmi.server.Unreferenced interface to get notification of when an RMI connection is lost. Similar to Peter's manual sending of keep alive messages, RMI itself sends keep alive messages and will call the unreferenced() method when it notices that a client is no longer responding to these keep alive messages.

Alternatively you can use WeakReferences (especially the WeakHashMap) to store your locks. When the distributed garbage collector is notified by RMI that a client is no longer connected, there will no longer be a reference on the lock, so it will be automagically cleared. Phil talks about the ramifications of this design in this thread.

Both these solutions assume that you have a unique connection per client, which implies some sort of connection factory on the server.

Regards, Andrew
 
Surya Kumar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew:
In my case i am using one data object where all the clients connects to. The design is such that all the clients connect to one single data access object. So unReference may not be feasible!!
 
Surya Kumar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Any way how much these are going to affect my scoring, if i did'nt implemnent the orphan clean up! Just wondering!
 
Surya Kumar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it necessary that we have to always clean up? I have a locking solution that work perfectly. I am using a FIFO queue of recordnumbers, that got notified in a sequence. This works fine. But if a client that's on the queuegoes down for whatever reasons other clients waiting on this record numbers are un rerachabl. Does anybody has any idea of how to do a proper thread cleaning? Or is it necessary at all? I am doing B&S. Thanxes in advance.
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Surya Kumar:
Is it necessary that we have to always clean up? I have a locking solution that work perfectly. I am using a FIFO queue of recordnumbers, that got notified in a sequence. This works fine. But if a client that's on the queuegoes down for whatever reasons other clients waiting on this record numbers are un rerachabl. Does anybody has any idea of how to do a proper thread cleaning? Or is it necessary at all? I am doing B&S. Thanxes in advance.


You need to associate a Data instance or some kind of Client instance with each locked record. If that Client or Data instance times out, gets unreferenced, gets closed or garbage collected you need to search through the lock map and unlock any orphaned locks.

The unlocking should be driven by your network code, since its the only place you can tell that a client has gone away. Both sockets and RMI provide ways to determine this, but they are not especially reliable since TCP won't inform a server if a client simply disappears. I've taken the approach of using an application level keep alive message and server timer to deal with this. It's described in my responses to this topic.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11945
212
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Surya,

As long as you document that you have not done any clean up of orphaned locks (and why), then you should not loose any marks.

Regards, Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic