数据处理-Spring Batch Scaling and Parallel Processing
承蒙各位抬爱,鄙人的一篇关于Spring Batch的博客《Spring Batch之进阶》有很多人浏览。说明有很多人工作中用到这个spring batch框架进行批量任务处理,也说明对这个框架还有不少不熟悉的地方,鄙人也是。That is to say,我们有必要加强学习,不然三天不学习,赶不上×××。这里就来继续说说Spring Batch Scaling and Parallel Processing那些事。这个标题的确不小,可伸缩和并行处理,的确是批量处理的很重要的特性,只有很好解决这些问题,才能成为一个完整的批量处理框架。本人GIT了一个项目:https://github.com/stylelyl/webatch.git,里面做了几个模式的实践,可以作为一个很好的理解,实际动手跑一跑。 Spring Batch的官方说明文档:https://docs.spring.io/spring-batch/trunk/reference/html/scalability.html 1,Multi-threaded Step <step id="loading">
<tasklet task-executor="taskExecutor" throttle-limit="20">...</tasklet>
</step>
2,Parallel Steps <job id="job1">
<split id="split1" task-executor="taskExecutor" next="step4">
<flow>
<step id="step1" parent="s1" next="step2"/>
<step id="step2" parent="s2"/>
</flow>
<flow>
<step id="step3" parent="s3"/>
</flow>
</split>
<step id="step4" parent="s4"/>
</job>
使用STS的插件,来图形化的看看处理的流程图是什么样的。这样看起来就是一目了然了。我们一般把可以同时并行跑的步骤分别通过split来并行来跑。 3,Remote Chunking 4,Partitioning 上面所说的,可以通过代码https://github.com/stylelyl/webatch.git来实践下。 具体的项目怎么跑起来,不多说,说说里面的几个关键的类: CardInfoPagingItemReader:这个类使用了DAO的方式来查询,然后使用com.github.pagehelper来分页。 KeyListReader:首先读取所有的keys,loadKeys() 然后一条条记录处理,loadItem(KEY key) * 通过keyIterator来遍历所有的keys (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |