Commit 0665992c by Billy Larru

usando timer y timertask

parent 7fcea978
package salidasautomaticas.main; package salidasautomaticas.main;
import java.util.logging.Level; import java.util.Timer;
import java.util.logging.Logger; import salidasautomaticas.schedule.Temporizador;
import static org.quartz.CronScheduleBuilder.cronSchedule; import salidasautomaticas.services.SalidasServices;
import org.quartz.CronTrigger;
import static org.quartz.JobBuilder.newJob;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import static org.quartz.TriggerBuilder.newTrigger;
import org.quartz.impl.StdSchedulerFactory;
import salidasautomaticas.schedule.Planificador;
import salidasautomaticas.schedule.ProgramarSalidasJob;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) throws Exception {
SchedulerFactory sf = Planificador.getInstance().getSchedulerFactory(); Timer timer = new Timer();
Scheduler scheduler; // SalidasServices services = new SalidasServices();
try { // System.out.println(services.obtenerHorariosSalida());
scheduler = sf.getScheduler();
JobDetail job = newJob(ProgramarSalidasJob.class).withIdentity("job1", "group1").build();
CronTrigger trigger = newTrigger().withIdentity("trigger1", "group1").withSchedule(cronSchedule("0 43 15 * * ?"))
.build();
scheduler.scheduleJob(job, trigger); timer.schedule(new Temporizador(), 0, 3000);
scheduler.start();
} catch (SchedulerException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
} }
} }
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salidasautomaticas.schedule;
import java.util.Date;
import java.util.TimerTask;
/**
*
* @author sistem19user
*/
public class Temporizador extends TimerTask{
@Override
public void run() {
System.out.println(new Date());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment