简体   繁体   English

订购Spring Batch中的分区步骤

[英]Order partitioned steps in Spring Batch

I have implemented Spring batch partitioning and I was returning a Map<String, ExecutionContext> result = new HashMap<>(); 我已经实现了Spring批处理分区,并且正在返回Map<String, ExecutionContext> result = new HashMap<>(); from partition() method of Partitioner . Partitioner partition()方法开始。

My requirement is to start slave steps in specific order( Insertion Order to result map) and that is not happening with above Map . 我的要求是以特定顺序(从插入顺序到result图)开始从属步骤,而上述Map不会发生这种情况。

I tried to use Map<String, ExecutionContext> result = new LinkedHashMap<>(); 我试图使用Map<String, ExecutionContext> result = new LinkedHashMap<>(); and that is also not useful - any thread from map gets started randomly. 这也没有用-地图中的任何线程都是随机启动的。

I am using SimpleAsyncTaskExecutor as executor in master step configuration and concurrencyLimit parallel threads get started. 我在主步骤配置中使用SimpleAsyncTaskExecutor作为执行程序,并且concurrencyLimit并行线程开始使用。 If I set concurrencyLimit=1 , then I want first thread inserted to result map to get started and so on. 如果我设置concurrencyLimit=1 ,那么我要插入第一个线程以开始result映射,依此类推。

How can I implement this ordering? 如何执行此订购?

From Looking at code, along with above step you might need to override StepExecutionSplitter#split, I believe you can extend SimpleStepExecutionSplitter class and implement Split method, in split method you need to change set used for collecting StepExecution from HashSet to LinkedHashSet, if you want to consider restart as well then you might need to consider changing in getContexts method as well. 从查看代码开始,随着上述步骤的进行,您可能需要覆盖StepExecutionSplitter#split,我相信您可以扩展SimpleStepExecutionSplitter类并实现Split方法,在split方法中,您需要将用于收集StepExecution的集合从HashSet更改为LinkedHashSet。同时考虑重新启动,那么您可能还需要考虑在getContexts方法中进行更改。

Below is the snippet to add splitter. 以下是添加拆分器的代码段。

stepBuilders.get("partitionStep")
                .partitioner(slaveStep)
                .partitioner("myParitionerStep", partitioner)
                .taskExecutor(new SimpleThreadPoolTaskExecutor())
                .splitter(new SimpleStepExecutionSplitter(jobRepository, allowStartIfComplete, stepName, partitioner))
                .build()

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

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