Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

After RMI Connection lost

 
Song Lixin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11914
209
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Song Lixin
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11914
209
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11914
209
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11914
209
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic