Theres a API called Quartz, It's where your program can schedule "Jobs" and it will run it at that time.
Until I can give an example, try this link.
Edit:
First you have to create a class that implements org.quartz.Job. When you implement that you will have to implement the method execute(JobExecutionContext jobExecution)
, which is the method that will run when the "trigger" is fired.
To set up the Schedule:
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
// Retrieve a scheduler from schedule factory
Scheduler scheduler = null;
try {
scheduler = schedulerFactory.getScheduler();
}
catch (SchedulerException e) {
e.printStackTrace();
}
//Set up detail about the job
JobDetail jobDetail = new JobDetail("jobDetail", "jobDetailGroup", ImplementedJob.class);
SimpleTrigger simpleTrigger = new SimpleTrigger("Trigger Name","defaultGroup", DATE);
// schedule a job with JobDetail and Trigger
scheduler.scheduleJob(jobDetail, simpleTrigger);
// start the scheduler
scheduler.start();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…