Java-Timer and TimerTask (Another Example)

Program Program Source import java.util.Timer; import java.util.TimerTask; class TimerT extends TimerTask { float time = 3; public void run() { System.out.println(“time = “+time); time-=.50; } } public class Javaapp { public static void main(String[] args) { TimerT task = new TimerT(); Timer time = new Timer(); time.schedule(task,2000,500); try{ Thread.sleep(5000); }catch(InterruptedException ie) { System.out.println(“Thread Interrupted”); } … Read more…

Java-Timer and TimerTask

Timer and TimerTask Timer and TimerTask use to you can create a thread that runs in the background, waiting for a specific time. When the time arrives, the task linked to that thread is executed. Various options allow you to schedule a task for repeated execution, and to schedule a task to run on a … Read more…