Polling the server, bad idea?

Hey Guys

Ive got a quick question. My rmi client checks the server every 10 seconds to see if there is an update. I was wondering if this was costly to the server, calling a remote method constantly.

Steps:

1. The client registers with the server

2. the server sends a user object back to the client

3. the client checks this user object every 10 seconds to see if an update has occured

Code

method on client calling remote object

new Thread(new Runnable(){

publicvoid run()

{

while(true)

{

try

{

Thread.sleep(10000);

if(isConnected())

{

System.out.println(client.getMessages().size());

System.out.println("Thread..." + Thread.currentThread().getName());

}

else

{

System.out.println("ohoh");

System.out.println("Thread..." + Thread.currentThread().getName());

}

}

catch(InterruptedException ex)

{

ex.printStackTrace();

}

catch(RemoteException ex)

{

ex.printStackTrace();

}

}

}

}).start();

I did a test and on the client is showed that there was only one thread created, not many. This is okay, but what about the server?

Any thoughts

Cheers for any help

[2174 byte] By [FatClienta] at [2007-11-26 22:50:32]
# 1

Ask first do later... going to change that attitude

well i put a thread output on the server and it came up with this:

Thread....RMI TCP Connection(2)-192.168.1.5

That should mean thread2 for my ip address?

and i've only connected one client and the loop is still running. soo thats good right?

cheers

FatClienta at 2007-7-10 12:11:49 > top of Java-index,Core,Core APIs...
# 2
everything is dandy until you have hndreds of clientsWhat is a poll? How much data is sent/recvd?How busy is the server? Can the server use more threads to sevice clients?provide more requiremnet infoSean
DataVirtuea at 2007-7-10 12:11:49 > top of Java-index,Core,Core APIs...
# 3
why cant the server just tell the client when there is a change and skip all this polling?
_dnoyeBa at 2007-7-10 12:11:49 > top of Java-index,Core,Core APIs...
# 4
> That should mean thread2 for my ip address?It means the second connection accepted for any IP address, and that this one is for your IP address.
ejpa at 2007-7-10 12:11:49 > top of Java-index,Core,Core APIs...
# 5

thanks for the replys

The only reason i was trying polling was i dont understand enough yet to ask the server to send a request to a client.

How would the client be able to accept a request? It could if it was UnicastRemoteObject, this would still inolve listening, so a connection would have to be made from the Server to the Client.

How would you go around doing this? Callbacks maybe

FatClienta at 2007-7-10 12:11:49 > top of Java-index,Core,Core APIs...
# 6

> How would the client be able to accept a request? It

> could if it was UnicastRemoteObject, this would still

> inolve listening, so a connection would have to be

> made from the Server to the Client.

Yes.

> How would you go around doing this? Callbacks maybe

That's the same thing as above. It's either callbacks or polling, there is no third way.

ejpa at 2007-7-10 12:11:49 > top of Java-index,Core,Core APIs...
# 7
AFAIK there is nothing special. You simply export a remote object on the client. Then pass it to the server in one of the servers methods. That object is a listener.You don't need to start a registry on the client side for this.
_dnoyeBa at 2007-7-10 12:11:49 > top of Java-index,Core,Core APIs...