Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX : 2 small questions

 
Joe Lamothe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi every one,
I have to small questions for you.
first, when using RMI, if a client calling a method disconnect while the operation is in the middle of its completion on the server, does the called method complete on the server side even if the client is gone?
second, I'm using a LockManager in my solution and every operations are synchronized on it in the Data class (synchronized(lockManager). When calling the LockManager.lock() method, this method look if the requested recNo isn`t already used, if it is, then call wait(). The part I don`t like is that this method isn`t synchronized since it's all done in the Data class. Is it ok to have a method call wait without first calling something like syncrhonized(this)?
Thansk for your comments
 
Bharat Ruparel
Ranch Hand
Posts: 493
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Joe,
A couple of things that you may want to keep in mind while implementing the locking using the lock-manager or otherwise are:
1. Do not call a method that is synchronized from within a synchronized method or block. Nesting synchronized calls is a bad idea.
2. The wait method is always called on an object from a synchronized context (read block).
Does this help?
Regards.
Bharat
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Joe,
does the called method complete on the server side even if the client is gone?

Yes the method does complete, however unrefenced may be called before it completes.
Depending on what you are doing this may cause you some issues. For instance, if you are relying on unreferenced to release your locks, but the client dies while waiting for a lock, then unreferenced will be called, followed (some time later) by the lock being granted: this lock then becomes orphaned!
Some simple test code (I don't believe it requires comments, but if you disagree with me, ask for comments and I will add them):
First up the server. I set the lease value to 5 seconds so that we don't have to wait all day for the lease value to expire. The server side method takes 10 seconds to run, so the lease should expire while the method is running.

Now for the client side. It just starts a new thread which will call the remote object, wait 2 seconds, then exit without cleanup. So the 2 seconds + 5 second lease value = 7 seconds: therefore unrefenced should be called prior to the remote method completing.

The output (server side) when I ran this:

Regards, Andrew
 
Joe Lamothe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Andrew, this answers my question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic