首页 \ 问答 \ 使用Spring Batch动态处理多个批处理文件并生成相应的输出文件(Dynamically processing multiple batch files and generating corresponding output files with Spring Batch)

使用Spring Batch动态处理多个批处理文件并生成相应的输出文件(Dynamically processing multiple batch files and generating corresponding output files with Spring Batch)

我最近开始学习Spring Batch,以便利用它的一些更高级的功能,如异步批处理,​​作业停止和调度来替换一些现有的批处理功能,并实现新的批处理功能。 现在,我正在试图弄清楚如何动态处理多个批处理文件并为每个输入文件生成“收据”文件,我对Spring Batch架构师的一些设计决策感到困惑。 看起来为了处理一个简单的平面CSV文件并生成输出,我将不得不手动破解我的ApplicationContext中的bean并在运行时手动设置它们的“资源”属性,以实现我想要的FlatFileItemReader和FlatFileItemWriter。 对于据称是多线程,高性能批处理框架的东西,这既不安全也不好。 我只是错过了一些东西吗?


I've recently started learning Spring Batch in order to make use of some of its more advanced features like asynchronous batch processing, job stopping, and scheduling to replace some existing batch processing functionality, and implement new batch processing functionality. Right now, I'm trying to figure out how to dynamically process multiple batch files and generate a "receipt" file for each input file, and I'm confused by some of the design decisions of the Spring Batch architects. It seems like in order to process a simple flat CSV file and generate the output, I'm going to have to manually hack the beans in my ApplicationContext and manually set their "resource" properties at runtime in order to achieve what I want with the FlatFileItemReader and FlatFileItemWriter. This is neither safe nor good practice for something that is allegedly a multi-threaded, high-performance batch processing framework. Am I just missing something ?


原文:https://stackoverflow.com/questions/4084625
更新时间:2023-09-23 10:09

最满意答案

多线程模型取决于应用程序。 它是否像网络连接一样以非常快的速度发送数据? 您是否通过连接在每个单独的数据上进行了复杂的计算? 计算是否相互独立或可以在个别处理后累积? 如果所有这些问题的答案都是肯定的,那么一个好的模型就是让Socket读取器线程将数据从网络写入队列,并从该队列读取几个线程并计算它读取的数据上的操作。 这个概念称为线程池。


The multi-threading model depends on the application. Is it like the network connection keeps sending data at a very fast rate? Are your complex calculations made on each single datum that you receive over the connection? Are the calculations independent of each other or can be accumulated after individual processing? If the answer to all these questions is a yes, then a good model would be to have a Socket reader thread write data from the network into a queue, and have several threads read from this queue and compute the operation on the datum that it read. This concept is known as a thread pool.

相关问答

更多
  • 多线程模型取决于应用程序。 它是否像网络连接一样以非常快的速度发送数据? 您是否通过连接在每个单独的数据上进行了复杂的计算? 计算是否相互独立或可以在个别处理后累积? 如果所有这些问题的答案都是肯定的,那么一个好的模型就是让Socket读取器线程将数据从网络写入队列,并从该队列读取几个线程并计算它读取的数据上的操作。 这个概念称为线程池。 The multi-threading model depends on the application. Is it like the network connecti ...
  • 好的,现在我已经弄明白了。 正如@Veedrac所写,Python对浮点数使用双精度,这是计算偏差的原因。 要在Processing中解决此问题,如果使用Java数学类中的数学函数,则可以在数学函数中使用双精度数。 因此,不要使用默认的sqrt()函数(或任何其他数学函数),而是通过输入import java.lang.Math.*;来import java.lang.Math.*; java数学类import java.lang.Math.*; 在代码的开头。 要在处理类型中使用函数,例如Math.sqr ...
  • 我使用ExecutorService private static final int procs = Runtime.getRuntime().availableProcessors(); private final ExecutorService es = new Executors.newFixedThreadPool(procs); int tasks = .... int blockSize = (tasks + procss -1) / procs; List> ...
  • 你已经将你的线程的run()方法编码为: void MyThread::run() { forever { doSomething(); msleep(1000); } } 有几个问题: doSomething()不会占用零时间。 至少,你需要花费多少时间doSomething()所需时间,并且睡眠时间比1000ms短得多。 doSomething() 和 msleep()可能会花费不同的时间,因为您的线程永远不会被保证不被抢占,也不会保证在睡眠过期后可立即开始运行。 因此,您需要 ...
  • 使用回调,正如我在另一个答案中概述的那样,您可以收到失败通知,并cancel所有提交的作业。 (在我的示例中, Callback实现类可以引用添加了每个Future的Collection 。)对于已完成(或启动,取决于参数值)的任务, cancel不执行任何操作。 其余的将永远不会开始。 Using a callback, as I outline in another answer, you can be notified of a failure, and cancel all submitted jo ...
  • 在评论中,@ steboc提到使用sqlite作为可能的解决方案。 您可以使用任何数据库作为后端,但sqlite相当快,几乎不需要设置。 这是一个将一堆垃圾写入sqlite然后以组的形式读回来的例子: 首先加载一些软件包并设置环境: import pandas as pd import sqlite3 import string ## connect to a db. This db will be created if it does not exist conn = sqlite3.connect( ...
  • SELECT * FROM (SELECT * FROM table ORDER BY date DESC) WHERE rownum <= 40 将返回按date排序的前40行。 如果有可用于查找这些行的date索引,并且假设统计数据是最新的,则Oracle应选择使用该索引来标识所需的40行,然后对该表执行40个单行查找检索其余的数据。 如果你想要的话,你可以在内部查询中抛出一个/*+ first_rows(40) */提示,尽管这应该没有任何作用。 有关分页 ...
  • 没有办法在double上获得BigDecimal精度。 double s具有双精度。 如果您想保证精确的结果,请使用BigDecimal 。 您可以使用long来创建自己的变量来存储整数部分,使用int来存储小数部分 - 但是为什么要重新发明轮子。 任何时候使用double s你可以从双精度问题中填充。 如果你在一个地方使用它们,你可以在任何地方使用它们。 即使您只使用它们来表示数据库中的数据,然后将数据四舍五入到精度,您将丢失信息。 There is no way to get BigDecimal pr ...
  • 首先,回答任何性能问题的唯一方法是分析应用程序。 我正在使用VS 2012内置的分析器 - 还有其他的https://stackoverflow.com/a/100490/19624 从最初的代码读取开始,即静态分析,跳出来的唯一一件事就是在循环内部不断重新分配Temp; 这不是有效的,如果可能的话,需要移出循环。 使用分析器,您可以看到发生了什么: 我首先使用您发布的代码进行了分析,(对于您发布问题的完整可编辑示例的最高分,如果您还没有,我现在不会回答这个问题)。 这告诉我批量是在循环的内部,我将分配移动 ...
  • 设置交集是关联的 ,因此适合并行折叠 (这是MapReduce的许多用例之一)。 对于每对集合((1,2),(3,4),...),您可以计算每对的交集,并将结果放入一组新的集合中,这些集合的大小将为一半。 重复,直到你只剩下一套。 交叉操作的总数将等于组的数量减1。 然而,启动数百万个线程会使您的计算机陷入困境,因此您可能希望使用线程池 :创建一些接近您可用的CPU核心数量的线程,并创建任务列表,其中每个任务是两个要交叉的集合。 每个线程重复检查任务列表并获取第一个可用任务(确保以线程安全的方式访问任务列表 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)