gpt4 book ai didi

Java批处理作业监听器afterJob获取作业的id

转载 作者:太空宇宙 更新时间:2023-11-04 12:25:49 25 4
gpt4 key购买 nike

如何检测正在调用 afterJob 监听器的已完成作业的作业 ID?我的工作正在批处理中开始,并且我有监听器。

我的作业名为 PayrollJob,监听器为 PayrollJobListener

<job id="payroll" xmlns="http://xmlns.jcp.org/xml/ns/javaee" version="1.0">
<listeners>
<listener ref="payrollJobListener"/>
</listeners>
<step id="process">
<listeners>
<listener ref="payrollItemWriteListener"/>
<listener ref="payrollSkipProcessorListener"/>
<listener ref="payrollSkipReadListener"/>
<listener ref="payrollSkipWriteListener"/>
<listener ref="payrollChunkListener"/>

</listeners>
<chunk item-count="5">
<reader ref="PayrollItemReader"></reader>
<processor ref="PayrollItemProcessor"></processor>
<writer ref="PayrollItemWriter"></writer>



</chunk>
</step>
</job>

以及带有监听器的类

@Named()
public class PayrollJobListener extends AbstractJobListener {

@Override()
public void beforeJob(){};

@Override()
public void afterJob(){
System.out.println("i need a id of a job calling this method");
};
}

最佳答案

您可以注入(inject) JobContext。

@Named()
public class PayrollJobListener extends AbstractJobListener {

@Inject
private JobContext jobContext;

@Override()
public void beforeJob(){};

@Override()
public void afterJob(){
long id = this.jobContext.getExecutionId();
String name = this.jobContext.getJobName();
};
}

关于Java批处理作业监听器afterJob获取作业的id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38397751/

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