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

Tiger Locking and RMI

 
Liang Anmian
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After some thinking, I've decided to use Tiger for my SCJD assignment. However, I have a big issue over here.

I do know that RMI doesn't guarantee anything in terms of thread usage. This is the cause of my worry currently. I will like to use the new ReentrantLock class to implement locking. However, according to the Tiger API documentation, lock and unlock must be called by the exact same thread, otherwise an exception is thrown. This will mean that when I call unlock on the ReentrantLock object, the current thread must be the one that calls lock. The problem is that if I use RMI, I cannot control which thread on the server will service the client request. As a result, if a client calls lock successfully, unlock may (actually most likely) fail later on, since I can't guarantee that the unlock call will be executed in the same thread.

So my question is, does this mean that socket is my only option if I use the ReentrantLock class?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does sound like it, unless you go and create an elaborate thread administration in the server.
You could give each client an attribute (like a session in HTTP) to indicate the serverside thread it uses and create a mechanism to keep the client linked up with that particular thread.

Haven't tried to create something like this myself, but when I think of it is sounds like an interesting experiment
 
Liang Anmian
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok looks like there's no other alternatives then. I will go for the socket solution.

I just read the specs again. It says that if I go for the socket option, I must send serialized objects over. But, what type of object? Any type, as long as it is an object? Array is an object too, so it is legal as well?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as you can serialise them... Remember you can only serialise something if everything it contains can be serialised as well.
 
Liang Anmian
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. And that means I'm not going to use any object. I will just use a String array, since it's an object too, and can be serialized. LOL!

Thanks anyway.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic