Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Job scheduling
Job scheduling [message #247622] Mon, 04 February 2008 14:34
Tom Cx is currently offline Tom CxFriend
Messages: 13
Registered: July 2009
Junior Member
Hi,

I've looked into the article : On the Job: The Eclipse Jobs API
( http://www.eclipse.org/articles/Article-Concurrency/jobs-api .html)
and have some question about it

final Job job = new Job("Long Running Job") {
protected IStatus run(IProgressMonitor monitor) {
try {
while(hasMoreWorkToDo()) {
// do some work
// ...
if (monitor.isCanceled()) return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
} finally {
schedule(60000); // start again in an hour <= (1)
}
}
};
job.addJobChangeListener(new JobChangeAdapter() {
public void done(IJobChangeEvent event) {
if (event.getResult().isOK())
postMessage("Job completed successfully");
else
postError("Job did not complete successfully");
}
});
job.setSystem(true);
job.schedule(); // start as soon as possible <= (2)


The line (1) reschedules a job to run after an hour again. Line (2)
launches the job for the first time. My question is how can you schedule
(2) so that it start at a specific day and time. Eg We are Monday and I
want to schedule this to start the first time on Sunday. Do you have to
calculate the difference from the moment you are scheduling till the
day/hour you want to schedule or is there some mechanism to do this in a
more easy way.

In fact what i want to reach is an equivalent of the code below which
schedules a task to run via java.util.timer eg every Sunday at midnight:

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class ReportGenerator extends TimerTask {

public void run() {
System.out.println("Generating report");
//TODO generate report
}

}

class MainApplication {

public static void main(String[] args) {
Timer timer new Timer();
Calendar date = Calendar.getInstance();
date.set(
Calendar.DAY_OF_WEEK,
Calendar.SUNDAY
);
date.set(Calendar.HOUR, 0);
date.set(Calendar.MINUTE, 0);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);
// Schedule to run every Sunday in midnight
timer.schedule(
new ReportGenerator(),
date.getTime(),
1000 * 60 * 60 * 24 * 7
);
}
}

Tnx in advance for the info and help !,
Tom
Previous Topic:Problem running project in console
Next Topic:Software Update Connection Problem
Goto Forum:
  


Current Time: Sat Oct 19 08:53:51 GMT 2024

Powered by FUDForum. Page generated in 0.06595 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top