What is the best way to kill a thread in a timer such that every time the timer runs, it kills the previous thread before starting a new one?
Code:
public class MapTimer extends TimerTask{ public void run() { try { connected = startConnection(); sendMessage(this.message); System.out.println("Sending message111 ..."+this.message); serverquerystring=receiveMessage(); thread = new Thread() { public void run() { try { System.out.println("In run.."); checkquery(serverquerystring); } catch (Exception ex) { ex.printStackTrace(); } } }; thread.start(); // write post-action user code here } catch(Exception e){ System.out.println("Error "+e); } } }
Comment