Java 多文件编写器的Spring批处理唯一名称
我在应用程序中使用spring批处理。我在步骤级别使用spring批处理的多线程 以下是我的配置:Java 多文件编写器的Spring批处理唯一名称,java,multithreading,spring,spring-mvc,spring-batch,Java,Multithreading,Spring,Spring Mvc,Spring Batch,我在应用程序中使用spring批处理。我在步骤级别使用spring批处理的多线程 以下是我的配置: <step id="testStep"> <tasklet task-executor="taskExecutor" throttle-limit="5"> <chunk reader="reader" writer="writer" commit-interval="10"> &
<step id="testStep">
<tasklet
task-executor="taskExecutor" throttle-limit="5">
<chunk reader="reader" writer="writer"
commit-interval="10">
</chunk>
</tasklet>
</step>
<bean id="writer" class="org.springframework.batch.item.file.FlatFileItemWriter"
scope="step">
<property name="resource" value="file:${output.file.location.directory}/<<<NEED TO PASS CURRENT EXECUTING THREAD NAME>>>" />
<property name="appendAllowed" value="true"></property>
<property name="lineAggregator" ref="aggregator" />
</bean>
所以,在flatfileitemWriter的resource属性中,我需要传递当前正在执行的线程名称,以便每个线程将写入一个单独的唯一文件
我可以在writer类中获取当前正在执行的线程名称,但不知道如何在spring确认文件中获取相同的名称
有这样做的想法吗?如果你愿意,你可以使用;使用此脚本语言,您可以使用标准java方法并检索当前线程名称,语法为{T(java.lang.thread).getCurrentThread().getName()}
以更清晰的方式,使用将当前线程名称注入步骤执行上下文(例如,
currentThreadName
key)并以标准方式从步骤xml配置中检索
<property name="resource" value="file:${output.file.location.directory}/#{stepExecutionContext['currentThreadName']}" />