简体   繁体   English

如何在另一个作业中进行异步Spring Batch作业

[英]How to make an asynchronous spring batch job with in another job

I am trying to create an Spring batch asynchronous job with in another job. 我正在尝试在另一个作业中创建一个Spring批处理异步作业。 Say Job-1 should be completed and Job-2 should be executed. 说Job-1应该完成,而Job-2应该执行。 But problem is Job-1 is waiting till Job-2 is getting completed which i don't want. 但是问题是Job-1正在等待Job-2完成,这是我不想要的。 I have used JobStep as well but it is happening in an synchronous way and not helpful. 我也使用过JobStep,但是它是以同步方式发生的,没有帮助。 Can some one help me how to use Asynchronously where Job-1 should not wait till Job-2 is completed ? 有人可以帮助我如何在Job-1不等Job-2完成之前异步使用它吗? Sample xml snippet below 下面的示例XML代码段

<bean id="taskExecutorAsync" class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
<bean id="jobLauncherAsync" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
        <property name="jobRepository" ref="jobRepository" />
        <property name="taskExecutor" ref="taskExecutorAsync" />
</bean>

<bean id="CreationProcess" class="test.CreationProcess">
        <property name="jobLauncher" ref="jobLauncherAsync" />
        <property name="jobRepository" ref="jobRepository" />
        <property name="jobExplorer" ref="jobExplorer" />           
</bean>

Thanks 谢谢

您可以使用SimpleAsyncTaskExecutor执行程序来避免阻塞。

I tried to create a separate thread, returned back and new thread updated the details. 我试图创建一个单独的线程,返回并新线程更新了详细信息。 Unable to create a new asynchronous spring batch job with in another job. 无法在另一个作业中创建新的异步Spring Batch作业。

In short, you can't using the JobStep . 简而言之,您不能使用JobStep The reason is because a Job is a state machine with each Step serving as a state. 原因是因为Job是一个状态机,每个Step作为一个状态。 In order for the Job to transition to the next state (aka complete in your use case), the current state (your child job) needs to complete. 为了使Job过渡到下一个状态(在您的用例中又完成),当前状态(您的子作业)需要完成。

You can launch jobs from other jobs, but to do so, you'll need to write a Tasklet to launch the job on a new thread (using a TaskExecutor ) and return immediately. 您可以从其他作业启动作业,但要这样做,您需要编写Tasklet以在新线程上启动作业(使用TaskExecutor )并立即返回。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM