aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI TCP Connection(4)-192.168.2.149 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI TCP Connection(4)-192.168.2.149" Watch "RMI TCP Connection(4)-192.168.2.149" New topic
Author

RMI TCP Connection(4)-192.168.2.149

dennis du
Ranch Hand

Joined: Dec 31, 2004
Posts: 59
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!!!


-------------------------------<br />OCP 9i <br />SCJP/SCJD/SCWCD(92%)/SCDJWS<br />XML(IBM Test 141)<br />Who is the next?SCBCD<br />SCBCD/CCNA/CCNP/PMP<br />not sure
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11481
    
  94

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


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
dennis du
Ranch Hand

Joined: Dec 31, 2004
Posts: 59
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.
 
Consider Paul's rocket mass heater.
 
subject: RMI TCP Connection(4)-192.168.2.149