• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RMI TCP Connection(4)-192.168.2.149

 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
First, you drop a couch from the plane, THEN you surf it. Here, take this tiny ad with you:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic