Meaningless Drivel is fun!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes After RMI Connection lost Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "After RMI Connection lost" Watch "After RMI Connection lost" New topic
Author

After RMI Connection lost

Song Lixin
Greenhorn

Joined: Nov 11, 2003
Posts: 19
Hello, ranchers!
I am nearly finished after several months. I have implmented <code>unreferenced</code> interface at server side so that when a client lost connection, the server knows that. My point is, while the server knows the lost, how can the client know that?

Yesterday I just start a client and a server, after several hours, I saw that the server had detected the lost connection while the client knew nothing. I traced the connection variable, it is not null! So I have no idea where to insert re-connect code.(One way to turn around is to connect everytime the server need a remote call). Can someone help me?

(Also, I found that when there are more that 20 concurrent clients, the request will be denied)


SCJP1.2<br />SCJD<br />SCMAD
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Song,

I have implmented <code>unreferenced</code> interface at server side so that when a client lost connection, the server knows that. My point is, while the server knows the lost, how can the client know that?


The client will probably find out the hard way next time it tries to call a remote method - a RemoteException will be thrown.

This should be reasonable behavior in most cases. Quite often neither the client nor the server care about dropped connections. Sometimes though, your server needs to run clean up code (for example removing orphaned locks), which is where the Unreferenced interface comes into play.

If you really want your client to get notification, you could set it up as a callback server. Some candidates have done this in order to automatically update all clients whenever a record is booked by any one of the clients using the Observable pattern (not needed for this assignment). From memory what you need to do is export your client class (see UnicastRemoteObject.exportObject()) and then have the server class connect to it. As long as your client class is also implementing Unreferenced, it should also get notification when the server dies.

(Also, I found that when there are more that 20 concurrent clients, the request will be denied)


Normally there is no problem with hundreds of connections, however there may be a problem if a large number of clients all try to connect simultaneously - possibly put a little delay into your connection loop, and they should all work (there were some reports of Windows XP limiting numbers of connections as well, but I don't know the full details).

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Song Lixin
Greenhorn

Joined: Nov 11, 2003
Posts: 19
Thx Andrew!
1. Because I am at the final step of the program. I will choose to catch the RemoteException and make a retry.
2. I wrote the test code that spawn many threads and connect to the server simultaneously. Some threads got failed when the number of thread is set to more than 25 also. For example, when there are 100 threads, then maybe 80 threads will be able to connect to the server. I limit the Max concurrent client to 20 because in this way, the user get a Normal failure.(The client will get a prompt "Load too heavey")

[ November 10, 2004: Message edited by: Song Lixin ]
[ November 10, 2004: Message edited by: Song Lixin ]
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Song,

2. I wrote the test code that spawn many threads and connect to the server simultaneously.


I suspect that it is the simultaneous attempts to connect that are the problem. Try putting a half second delay in your loop making connections, and see how many connections you can make.

Regards, Andrew
Song Lixin
Greenhorn

Joined: Nov 11, 2003
Posts: 19
Thx Andrew.
So what you mean is that I need not enfore a 20 limit?
I know only when using the testing code can I get the connection failure.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Song,

What I am suggesting is that you should try adding the delay to your test code and see if it solves your problem. If so, then you do not need your arbitrary limit of 20 connections (this was also suggested in the topic "The concurrent problem about RMI").

Alternatively you could look at the topic "More than 17 clients CRASH?!". I particularly like Thomas Paul's suggestion in that.

Regards, Andrew
Song Lixin
Greenhorn

Joined: Nov 11, 2003
Posts: 19
Thx Andrew!
I declared an array of DBClient and initiate one by one. It seems no problem with 100 DBClient initiation. Because all the connections are made in one for phrase, The time difference must be quite little.

If I will set a limitation on the number of concurrent clients, I think 100 is quite good. Right?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11404
    
  81

Hi Song,

That depends on your reasoning behind the "100", which is something you should be putting in your design decisions document. As long as you can justify why you think 100 connections is a reasonable number, you should be fine.

Regards, Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: After RMI Connection lost
 
Similar Threads
Client Connecting to Multiple Servers
Restlet connection is not closing
Check Socket Connection State
connection problem...
Connection time out in applets