gpt4 book ai didi

java - Quartz Scheduler 为单个作业设置多个触发器时出现问题

转载 作者:行者123 更新时间:2023-11-30 07:36:43 24 4
gpt4 key购买 nike

我正在尝试为单个作业创建多个触发器。一切看起来都很好,直到我使用 scheduler.scheduleJobs(triggerAndJobs, true);
Maven 显示构建失败,有 1 个错误和 0 个警告,没有更多信息。失败的原因可能是什么?

 public void createControlTask(String name, String id, String freq) throws SchedulerException {
JobBuilder jobBuilder;
JobDetail jobDetail;
TriggerBuilder trigBuilder;
Trigger trigger = null;
CronTrigger trig;
String cronFreq;
List triggerList = new ArrayList();
Map<JobDetail,List<Trigger>> triggerAndJobs = new HashMap<JobDetail, List<Trigger>>();

log.info("in createSchedulerTask() for : " + name);
if ((freq != null) && !(freq.equals("As needed"))) {

jobDetail = JobBuilder.newJob(QuraJob.class)
.withIdentity(name + "_JOB", Constants.CONTROL_TASK)
.usingJobData(Constants.NAME, name)
.usingJobData(Constants.ID, id)
.usingJobData(Constants.FREQUENCY, freq).build();

if(freq.equals(Constants.MONTHLY)){
String[] months = Constants.MONTHLY_PERIOD;
for(int i = 0; i < months.length; i++)
{
String cron_for_month = props.getProperty("quartz.cron."+months[i]);

trig = (CronTrigger) TriggerBuilder
.newTrigger()
.withIdentity(name + "_TRIGGER", Constants.CONTROL_TASK)
.withSchedule(CronScheduleBuilder.cronSchedule(cron_for_month))
.build();

triggerList.add(trig);
}
}
triggerAndJobs.put(jobDetail, triggerList);
if (!scheduler.isStarted()) {
scheduler.start();
}
//scheduler.scheduleJobs(triggerAndJobs, true);
//map.put(jobDetail, triggerList);
//scheduler.scheduleJob(map, true);

}
else
log.info("Freq [" + freq + "] is not a schedulable value. So not scheduling a task for this control");
}

错误如下:

 Compiling 63 source files to C:\Users\Rahul\git\et\datacollector\target\classes
[DEBUG] incrementalBuildHelper#afterRebuildExecution
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Found 1 error and 0 warnings.
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] quadrisk-parent .................................... SUCCESS [ 2.765 s]
[INFO] data-collector ..................................... FAILURE [ 24.602 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 29.138 s
[INFO] Finished at: 2016-02-09T17:25:39+05:30
[INFO] Final Memory: 16M/80M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project data-collector: Compilation failure
[ERROR] Found 1 error and 0 warnings.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project data-collector: Compilation failure
Found 1 error and 0 warnings.

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:197)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
Found 1 error and 0 warnings.

at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:858)
at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:129)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 20 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :data-collector

最佳答案

因此,最终的需要是为单个 quartz 作业创建多个触发器。所以下面的代码帮助我做到了。

public void createControlTask(String name, String id, String freq) throws SchedulerException {
JobBuilder jobBuilder;
JobDetail jobDetail;
TriggerBuilder trigBuilder;
Trigger trigger = null;
CronTrigger trig;
Set<Trigger> triggerList = new HashSet<Trigger>();
String[] months = null;
String cronFreq;
log.info("in createSchedulerTask() for : " + name);
if ((freq != null) && !(freq.equals("As needed"))) {
jobBuilder = JobBuilder.newJob(QuraJob.class);
jobBuilder = jobBuilder.withIdentity(name + "_JOB", Constants.CONTROL_TASK);
jobBuilder = jobBuilder.usingJobData(Constants.NAME, name);
jobBuilder = jobBuilder.usingJobData(Constants.ID, id);
jobBuilder = jobBuilder.usingJobData(Constants.FREQUENCY, freq);
jobDetail = jobBuilder.build();
log.info("Job created -- [" + jobDetail.getKey() + "]");
if(freq.equals(Constants.MONTHLY)){
months = Constants.MONTHLY_PERIOD;
}
if(freq.equals(Constants.QUARTERLY)){
months = Constants.QUARTERLY_PERIOD;
}
if(freq.equals(Constants.ANNUALLY)){
months = Constants.ANNUALLY_PERIOD;
}
if(freq.equals(Constants.HALF_YEARLY)){
months = Constants.HALF_YEARLY_PERIOD;
}
for(int i = 0; i < months.length; i++){
cronFreq = props.getProperty("quartz.cron."+months[i]);
trigBuilder = TriggerBuilder.newTrigger();
trigBuilder = trigBuilder.withIdentity(name + "_TRIGGER_" + i, Constants.CONTROL_TASK);
trigBuilder = trigBuilder.startNow();
trigBuilder = trigBuilder.withSchedule(CronScheduleBuilder.cronSchedule(cronFreq));
trigBuilder = trigBuilder.forJob(jobDetail);
trigger = trigBuilder.build();
triggerList.add(trigger);
}
if (!scheduler.isStarted()) {
scheduler.start();
}
if(triggerList.size() > 0){
scheduler.scheduleJob(jobDetail,triggerList,true);
for(int j=0;j<scheduler.getTriggersOfJob(jobDetail.getKey()).size();j++){
log.info((scheduler.getTriggersOfJob(jobDetail.getKey()).get(j)).getNextFireTime()+ "" );
}
}
}
else
log.info("Freq [" + freq + "] is not a schedulable value. So not scheduling a task for this control");
}

关于java - Quartz Scheduler 为单个作业设置多个触发器时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35290271/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com