Hello!
I'm new to threads and I've written a small application which sends
ping commands to the spefified host! The class responsible for that
is like this one
private class PingMachine extends Thread{
PingMachine(
String machine)
{
host = machine;
}
public void run(){
while(true){
try{
Process p = Runtime.getRuntime().exec("ping -t " + host);
InputStream in = p.getInputStream();
InputStreamReader rin = new InputStreamReader(in);
BufferedReader bin = new BufferedReader(rin);
String s;
System.out.println(new Date());
while ((s=bin.readLine()) != null) {
System.out.println(s);
}
}catch(Exception ex){
ex.printStackTrace();
}
}
}
}
For each button click I start a new
thread PingMachine pinger = new PingMachine(hostField.getText().trim());
pinger.start();
What I want to ask is that how can I keep refernces to each newly created thread and destroy it when no londer needed?
Best Regards, Fedai!