Andy897
Andy897

Reputation: 7133

Java timer task first run

I have a Java timer task for generating daily reports. When I invoke a Java class (that schedules that timer task) through linux terminal, instead of scheduling the first run at the given time it runs as soon as command is executed. Can someone please suggest why is it so ..

I am using scheduleatfixedrate for scheduling it.

Forgot to add that I am using java 1.5 Here is the method def

Code snippets:

timer.scheduleAtFixedRate(new ArchiveTask(), archiveSchedule, 86400000);

public class ArchiveTask extends TimerTask {

public void run() {
        backUpFiles();
    }

public void backUpFiles(){
            ...}
}

Upvotes: 0

Views: 556

Answers (2)

Andy897
Andy897

Reputation: 7133

The problem as suggested by dreamer was this that the second argument was 0.

Upvotes: 0

Ankit Kumar
Ankit Kumar

Reputation: 1463

To add to what i said earlier, here is the working code:

public class Test {
static Timer timer = new Timer();

public static void main(String[] args) {
    timer.scheduleAtFixedRate(new timeTask(), 10000, 10000);
}

private static class timeTask extends TimerTask {

    @Override
    public void run() {
        System.out.println("inside task");
    }

}
}

Upvotes: 2

Related Questions