2022-06-03 09:53
我复制过去,修改了一下,可以用了,下面修改办法:
第一:依赖直接拿去,不用百度上找
org.quartz-scheduler
quartz
2.2.1
第二、QuartzPlugin.java(插件类)代码的修改:
(1):所有Throwables.propagate(e); 改成e.printStackTrace();
(2): public QuartzPlugin(String jobConfig) {
this.jobConfig = jobConfig;
this.confConfig = "quartz_config.properties"; //修改部分
}
public QuartzPlugin() {
this.jobConfig = "quartz_job.properties";//修改部分
this.confConfig = "quartz_config.properties";//修改部分
}
quartz_job.properties 和quartz_config.properties放在src/main/resources下面即可
(3):
private List jobs = new ArrayList();
private SchedulerFactory sf;
private static Scheduler scheduler;
private String jobConfig;
private String confConfig;
private Prop jobProp;//修改部分
private void loadJobsFromProperties() {
if (StrKit.isBlank(jobConfig)) {
return;
}
jobProp = PropKit.use(jobConfig);//修改的部分
String jobArray = jobProp.get("jobArray");
if (StrKit.isBlank(jobArray)) {
return;
}
String[] jobArrayList = jobArray.split(",");
for (String jobName : jobArrayList) {
jobs.add(createJobBean(jobName));
}
}
第三:configPlugin 方法添加
//配置定时插件
QuartzPlugin qp = new QuartzPlugin();
me.add(qp);
第四:quartz_job.properties 里面修改定时时间
#5秒执行
task1.cron=0/5 * * * * ?
测试类:
public class Task1 implements Job{
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("5秒执行一次!");
}
}
2022-03-07 14:56
@zzutligang 说错了cookie放UUID,那你可以用redis去做登录限制