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

RMI TCP Connection(4)-192.168.2.149

 
dennis du
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to do some orphan threads monitoring(I use RMI).
So when a reference is comming,I save it(thread object) into a map.

Then I will detect the status of the threads,if the thread is dead,I will release all the resource by it.

But the problem is: After a connecttion is lasting about 6 seconds,the thread is dead.(RMI TCP Connection(4)-192.168.2.149 is dead).

You know, at that time,I can do search and booking through the client GUI.

How to solve it?

Thanks a lot!!!
 
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 Dennis,

The RMI specification is quite explicit that you cannot rely on thread behavior at all. So you cannot rely on two clients getting different threads (they may get the same thread), likewise you cannot rely on one client using the same thread for two subsequent method calls (it may get a new thread or may use a thread that was previously used by another client.

I have some sample code which demonstrates this in the topic "Using Thread ID for lock owner not safe?".

As an alternative, you might want to look at using an RMI Factory to create a new connection object per client. You could then use RMI's Unreferenced interface or the finalize() method to do clean up. You could look at the topic "Does the lock associate session ID or customer ID?" for some examples of that.

Another alternative is (again using an RMI Factory to create a new connection object per client) using the unique object in a WeakHashMap - the lock will then be automagically removed if the client crashes. Some of the issues related to that are discussed in the topic "Single table / Simple Locking - WeakHashMap vs WeakReferences".

Regards, Andrew
 
dennis du
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Andrew,

You are right . I just find that :
when a client get a rmi reference,the server does not spawn
a thread for it. When it call method from the server object
,the server spawn a thread for it.
But after the call returned,the connection is not kept by the
server.the server may release the connection any time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic