J
joshivaibhav
Hello,
I am running the following code, but it never terminates:
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class YetAnotherTimer
{
private static Integer iCount = 0;
public static void main (String args[])
{
int numberOfMillisecondsInTheFuture = 10000; // 10 sec
Date timeToRun = new
Date(System.currentTimeMillis()+numberOfMillisecondsInTheFuture);
Timer timer = new Timer();
timer.schedule(new TimerTask()
{
public void run()
{
System.out.println("Generating report");
iCount++;
System.out.println("Count is: " + iCount);
}
}, timeToRun);
}
}
It simply waits in the memory. I am looking for functionality where the
timer will execute a task at a predefined time and once the task is
finished, the timer thread will exit. I tried calling the method
cancel() from within the run() method, but still it does not terminate
the timer thread.
Please let me know.
Thanks,
Vaibhav
I am running the following code, but it never terminates:
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class YetAnotherTimer
{
private static Integer iCount = 0;
public static void main (String args[])
{
int numberOfMillisecondsInTheFuture = 10000; // 10 sec
Date timeToRun = new
Date(System.currentTimeMillis()+numberOfMillisecondsInTheFuture);
Timer timer = new Timer();
timer.schedule(new TimerTask()
{
public void run()
{
System.out.println("Generating report");
iCount++;
System.out.println("Count is: " + iCount);
}
}, timeToRun);
}
}
It simply waits in the memory. I am looking for functionality where the
timer will execute a task at a predefined time and once the task is
finished, the timer thread will exit. I tried calling the method
cancel() from within the run() method, but still it does not terminate
the timer thread.
Please let me know.
Thanks,
Vaibhav