package com.chinawiserv.platform.pfl.system.service.impl;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
import javax.annotation.Resource;
import org.quartz.DateBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.SimpleTrigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Component("tableTrigger")
public class TableTrigger
{
public static int j=0;
public static Scheduler sched = null;
public static SchedulerFactory sf;
static
{
try
{
sched = sf.getScheduler();
} catch (SchedulerException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// @Resource(name="tableJob")
// private TableJob tableJob;
// public TableJob getTableJob()
// {
// return tableJob;
// }
//
// public void setTableJob(TableJob tableJob)
// {
// this.tableJob = tableJob;
// }
public void run(String job,String group1) throws SchedulerException
{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
// 在当前时间15秒后运行
Date startTime = DateBuilder.nextGivenSecondDate(null, 15);
JobDetail job1 = null;
SimpleTrigger trigger = null;
job1 = JobBuilder.newJob(TableJob.class).withIdentity(job+UUID.randomUUID(), group1+ UUID.randomUUID()).build();
trigger = (SimpleTrigger) TriggerBuilder.newTrigger().withIdentity("aaaa1"+ UUID.randomUUID(), "bbbb1"+ UUID.randomUUID()).startAt(startTime).withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(10).repeatForever()).forJob(job1).build();
Date ft = sched.scheduleJob(job1, trigger);
break;
//System.out.println("big===="+Thread.currentThread().getId());
sched.start();
}
}
@Component("tableJob")
public class TableJob extends SuperTableJob implements Job
{
public static int i = 0;
private TableService tableServiceImpl;
public TableService getTableServiceImpl()
{
return this.tableServiceImpl = this.getApplicationContext().getBean(TableService.class);
}
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException
{
//System.out.println(Thread.currentThread().getId());
Table1 t = new Table1();
t.setTable1_id("sdfdsfdsf");
t.setTable_1_f1("sdfdsfdsf");
t.setTable_1_f2("sdfdsfdsf");
t.setTable_1_f3("sdfdsfdsf");
t.setTable_1_f4("sdfdsfdsf");
t.setTable_1_f5("sdfdsfdsf");
t.setTable_1_f6("sdfdsfdsf");
t.setTable_1_f7("sdfdsfdsf");
t.setTable_1_f8("sdfdsfdsf");
t.setTable_1_f9("sdfdsfdsf");
t.setTable_1_f11("sdfdsfdsf");
t.setTable_1_f12("sdfdsfdsf");
t.setTable_1_f13("sdfdsfdsf");
this.getTableServiceImpl().addTable(t);
}
}