querytz任务调度的代码

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
{
    sf = new StdSchedulerFactory();
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);

}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值