Scheduling a Timer Task to Run Repeatedly
int delay = 5000; // delay for 5 sec.
int period = 1000; // repeat every sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
// Task here ...
}
}, delay, period);
import ....?
Explanations nil.
Use Eclipse, then you dont have to mess with imports.
The package that contains Timer and TimerTask is in java.util
Nice
Simple and enough
perfect....
is it running?
yup.. running
yup running well...
This is for programmer who wants to understatnd the concept with code.
gud enough for simple sceduler
bro its not working i tried
try these codes
/*
Class : HeartBeatTask.java
Author : Atul
Date : May 09 Sunday
*/
import java.util.TimerTask;
public class HeartBeatTask extends TimerTask
{
private int timerInterval;
public HeartBeatTask(int timeInterval)
{
this.timerInterval=timeInterval;
}
public void run()
{
// add the task here
System.out.println("Repeat : In Run");
}
}
/*
Class : Test Timer.java
Author : Atul
Date : May 09 Sunday
*/
import java.util.TimerTask;
class TestTimer
{
public static void main(String[] args)
{
System.out.println("In Test Timer Class!");
java.util.Timer t1 = new java.util.Timer();
/*
Set the Timer Interval for the scheduler
in terms for milliseconds
HeartBeatTask tt = new HeartBeatTask(Timer Interval);
t1.schedule(tt, 0, Timer Interval);
*/
HeartBeatTask tt = new HeartBeatTask(100);
t1.schedule(tt, 0, 100);
}
}
PDF Creator
BMP to PDF Converter
EMF to PDF Converter
WMF to PDF Converter