我有一个弹簧批量集成的spring mvc应用程序。我的春季批处理作业通过cron触发器执行。
我的xml中有两个批处理作业。第二批作业工作正常,但是当我执行第一个批处理作业时,它执行第二个。
我认为我正在错误地注册我的工作。有人可以帮我解决可能出错的问题。
感谢
第二个作业定义(job-bulletin-bar-msg-update.xml)...
<job id="job-bulletin-bar-msg-update" xmlns="http://www.springframework.org/schema/batch">
<step id="step1">
<tasklet>
<chunk
reader="bulletinBarUpdateJdbcCursorItemReader"
writer="bulletinBarUpdateItemWriter"
commit-interval="1000" />
</tasklet>
</step>
</job>
第一个职位定义(job-daily-tran-counts.xml)......
<job id="job-daily-tran-counts" xmlns="http://www.springframework.org/schema/batch">
<step id="step1">
<tasklet>
<chunk
reader="dailyTranCountJdbcCursorItemReader"
writer="dailyTranCountItemWriter"
commit-interval="1000" />
</tasklet>
</step>
</job>
向调度程序和注册表添加作业....
<beans profile="pre,prod">
<!-- jobs -->
<import resource="./jobs/job-daily-tran-counts.xml" />
<import resource="./jobs/job-bulletin-bar-msg-update.xml" />
<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobDetails">
<list>
<ref bean="dailyTranCountJobDetail" />
<ref bean="bulletinBarMsgUpdateJobDetail" />
</list>
</property>
<property name="triggers">
<list>
<ref bean="dailyTranCountCronTrigger" />
<ref bean="bulletinBarMsgUpdateCronTrigger" />
</list>
</property>
</bean>
<!-- scheduling properties -->
<util:properties id="batchProps" location="classpath:batch.properties" />
<context:property-placeholder properties-ref="batchProps" />
<!-- triggers -->
<bean id="dailyTranCountCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="dailyTranCountJobDetail" />
<property name="cronExpression" value="#{batchProps['cron.dailyTranCounts']}" />
</bean>
<bean id="bulletinBarMsgUpdateCronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail" ref="bulletinBarMsgUpdateJobDetail" />
<property name="cronExpression" value="#{batchProps['cron.bulletinBarUpdateMsg']}" />
</bean>
<!-- job detail -->
<bean id="dailyTranCountJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.myer.reporting.batch.JobLauncherDetails" />
<property name="group" value="quartz-batch" />
<property name="jobDataAsMap">
<map>
<entry key="jobName" value="job-daily-tran-counts" />
<entry key="jobLocator" value-ref="jobRegistry" />
<entry key="jobLauncher" value-ref="jobLauncher" />
</map>
</property>
</bean>
<bean id="bulletinBarMsgUpdateJobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
<property name="jobClass" value="com.myer.reporting.batch.JobLauncherDetails" />
<property name="group" value="quartz-batch" />
<property name="jobDataAsMap">
<map>
<entry key="jobName" value="job-bulletin-bar-msg-update" />
<entry key="jobLocator" value-ref="jobRegistry" />
<entry key="jobLauncher" value-ref="jobLauncher" />
</map>
</property>
</bean>
</beans>
这是我的工作启动器详细信息类。我只是从其他地方复制了它......
public class JobLauncherDetails extends QuartzJobBean {
static final String JOB_NAME = "jobName";
private JobLocator jobLocator;
private JobLauncher jobLauncher;
public void setJobLocator(JobLocator jobLocator) {
this.jobLocator = jobLocator;
}
public void setJobLauncher(JobLauncher jobLauncher) {
this.jobLauncher = jobLauncher;
}
@SuppressWarnings("unchecked")
protected void executeInternal(JobExecutionContext context) {
Map<String, Object> jobDataMap = context.getMergedJobDataMap();
String jobName = (String) jobDataMap.get(JOB_NAME);
JobParameters jobParameters = getJobParametersFromJobMap(jobDataMap);
try {
jobLauncher.run(jobLocator.getJob(jobName), jobParameters);
} catch (JobExecutionException e) {
e.printStackTrace();
}
}
//get params from jobDataAsMap property, job-quartz.xml
private JobParameters getJobParametersFromJobMap(Map<String, Object> jobDataMap) {
JobParametersBuilder builder = new JobParametersBuilder();
for (Entry<String, Object> entry : jobDataMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value instanceof String && !key.equals(JOB_NAME)) {
builder.addString(key, (String) value);
} else if (value instanceof Float || value instanceof Double) {
builder.addDouble(key, ((Number) value).doubleValue());
} else if (value instanceof Integer || value instanceof Long) {
builder.addLong(key, ((Number) value).longValue());
} else if (value instanceof Date) {
builder.addDate(key, (Date) value);
} else {
// JobDataMap contains values which are not job parameters
// (ignoring)
}
}
//need unique job parameter to rerun the same job
builder.addDate("run date", new Date());
return builder.toJobParameters();
}
}
这是我的batch.properties ...
#http://quartz-scheduler.org/documentation/quartz-1.x/tutorials/crontrigger
cron.dailyTranCounts=0 15 07 * * ? *
cron.bulletinBarUpdateMsg=0 30 07 * * ? *
更多信息。为了尝试找到更多信息,我在org.springframework.batch.core.launch.support.SimpleJobLauncher上登录。
当我在spring配置中只启用了第一个作业时,日志显示job-daily-tran-counts大约需要2.5分钟才能执行...
[INFO] 2014-03-19 07:15:00,187 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-daily-tran-counts]] launched with the following parameters: [{run date=1395173700052}]
[INFO] 2014-03-19 07:17:43,934 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-daily-tran-counts]] completed with the following parameters: [{run date=1395173700052}] and the following status: [COMPLETED]
当我在spring配置中仅启用了两个作业时,日志显示job-daily-tran-counts大约需要8毫秒才需要更长的时间。即它什么都不做......
[INFO] 2014-04-15 07:15:00,225 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-daily-tran-counts]] launched with the following parameters: [{run date=1397510100128}]
[INFO] 2014-04-15 07:15:08,977 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-daily-tran-counts]] completed with the following parameters: [{run date=1397510100128}] and the following status: [COMPLETED]
[INFO] 2014-04-15 07:30:00,009 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-bulletin-bar-msg-update]] launched with the following parameters: [{run date=1397511000007}]
[INFO] 2014-04-15 07:30:05,217 org.springframework.batch.core.launch.support.SimpleJobLauncher run - Job: [FlowJob: [name=job-bulletin-bar-msg-update]] completed with the following parameters: [{run date=1397511000007}] and the following status: [COMPLETED]
答案 0 :(得分:2)
我有类似的问题。对我有用的是重命名step-id以使它们是唯一的。值得一试
答案 1 :(得分:0)
我有一个类似的问题,这是运行于Spring Boot版本2.1.10.RELEASE的spring批处理版本4.2.1.RELEASE,该版本由spring framework版本5.1.11.RELEASE支持。因此,这里(可能)存在一种情况,当框架“不平等地被当代人束缚”时会发生什么。要考虑的另一件事是作业存储库的持久性,这意味着在某些时候该作业将调用错误的步骤。这花费了很多调试中断点,尤其是在作业启动器周围。因此,我所做的是任意更改步骤的名称。在我的假设中,这将迫使框架检测步骤ID的更改并刷新数据库中的定义。有效。如果我坚持使用spring boot的spring batch版本,是否还在寻找step-id-name-calling问题是否可以解决自己的问题。
答案 2 :(得分:0)
我遇到了同样的问题,不得不重命名所有步骤。
在某处阅读 @EnableBatchProcessing(modular = true)
这可能会使作业保持在单独的“上下文”中