EXECUTING PING EVERY 4 SECS

Hi all, would like to apologise in advance if this question is too simple but then again i would like some opinions on this matter.

I am trying to ping 2 network elements every 4 seconds and then update the status on a gui. i would appreciate if anyone out there could suggest the best way this could be done so that performance is not undermined.

I am using runtime exec to execute the ping but what should i use to implement the timing factor for both the elements?

would really appreciate some opinions and lead on this.

thanks a lot.

[575 byte] By [swg1] at [2007-9-26 2:21:14]
# 1

Well the ping function should really be executing in its own thread, otherwise the GUI won't update properly. So, the simple way to do the timing is just to call "sleep(4000);" after each ping. If you're updating the GUI from a thread, you should use SwingUtilities invokeLater(myThread) instead of myThread.start();

artntek at 2007-6-29 9:26:06 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
Pinging has been answered a million times. Please search the board BEFORE you post.
filburt1 at 2007-6-29 9:26:06 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3

hi, thanks for helping me out.

what i need to do is to call a method of another class that does the ping and returns the response to the GUI class so can i put the sleep for 4 secs in the GUI class after the ping method has been called....i am wondering if that will affect the GUI ?

would really appreciate your suggestion.

thanks again

swg1 at 2007-6-29 9:26:06 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4

> what i need to do is to call a method of another class

> that does the ping and returns the response to the GUI

> class so can i put the sleep for 4 secs in the GUI

> class after the ping method has been called....i am

> wondering if that will affect the GUI ?

Yes - if you cause the main (event dispatch) thread to sleep, then the gui will be unresponsive during that time - it will not repaint if you try to update it from the ping method, and it also won't repaint if, say, you open or drag another window over it, or if you drag the gui itself, etc.

The way to do it is define a new thread://this is in your gui code:

Thread myThread = new Thread(){

public void run(){

// call your ping method here...

}

};

myThread.setPriority(2);

SwingUtilities.invokeLater(myThread);

artntek at 2007-6-29 9:26:06 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 5
hihi........
qaza at 2007-6-29 9:26:06 > top of Java-index,Archived Forums,New To Java Technology Archive...