Timeout a client app

I have a java GUI client/server application that uses swing classes and AWT . I need to timeout the client application after 4 hours. Does anyone have any tips of how to do this?

Do I try to timeout the RMI socket connection or do I try to use some sort of listener to see if there has not been any activity for 4 hours on the client? I'm not sure how to start.

[376 byte] By [nose-85a] at [2007-10-2 0:14:59]
# 1

Why not:

Every time there is activity on the RMI set a timer to occur after 4 hours, if you delete the old timer and create a new one every time the RMI has activity then you only have one timer and it will occur if, and only if, nothing has happened on the RMI for 4 hours. Youm can then deal with the RMI connection, etc as you want.

So :

java.util.Timer myTimer = new Timer();

// The timeout is in milliseconds.

myTimer.schedule(new MyHandler(), 0, 4*60*60*1000);

Above starts a timer that will occur after 4 hours.

Use:

myTimer.cancel();

myTimer.schedule(new MyHandler(), 0, 4*60*60*1000);

To cancel the old timer and start a new one.

MyHandler needs to extend java.util.TimerTask and do whatever you want. When you extend TimerTask you then implement the run() method:

public void run()

{

// Do your work here

}

run() is called if the timer ever occurs.

JimDinosaura at 2007-7-15 16:16:32 > top of Java-index,Archived Forums,Java 2 Software Development Kit (J2SE SDK)...