如何在计划作业之间共享数据
我正在编写一个调度程序,它获取 XML 数据并将其插入 MySQL DB - 并不简单。但我试图找到的问题或逻辑就在这里。 注意:我想在 Windows 环境中执行此操作,将来可能会为其他平台进行配置。
- 调度程序应每 5 分钟运行一次。
- 该脚本应该从 XML 中获取有关解析和收集数据字段的条件/配置,并且这些条件可从 MySQL 表中获取。
- 该表还定义了一个延迟,在此脚本应检查 XML 字段和字段之间的差异。延迟。
- 该脚本同时执行这两项操作,每 5 分钟运行一个脚本来收集 XML 并检查表 (MySQL) 中每个所述延迟的差异。
- 然后,该脚本读取 XML 数据字段并对其进行解析,然后仅收集从上述 MySQL 表中定义的数据字段。
- 仅当状态发生变化时收集的数据才会插入MySQL DB,并且该状态是从MySQL表中定义的。
反馈/建议:
- 由于延迟,我不确定应该如何将配置存储在脚本中,该脚本将在每个计划之间共享。
- 无论如何,是否可以在代码中使用
static
变量来存储这些数据?哪些将由不同的工作共享?或者不同的时间表? - 基本上,我应该如何实现这个?就性能而言,这是一种更好的方法。
感谢您抽出时间。
更新:
建议之一是使用 Java 代码作为 Windows 服务(?)我们可以在不同的作业之间共享一些通用数据吗? - 这有道理吗?
参考: Java 服务包装器
I am writing a scheduler which grabs XML data and inserts into MySQL DB - simple isn't. But the problem or the logic that I am trying to find is here. NOTE: I want to execute this in windows environment in future it might be configured for other platforms.
- Scheduler should run on every 5 mins.
- This script should fetch condition/configuration on what to parse and collect the data-fields from XML and these conditions are available from MySQL table.
- This table also defines a delay in which this script should check for the difference in the XML fields & delay.
- This script does both, one is running for every 5 mins to collect XML and check the difference in the table (MySQL) for every said delay.
- This script then reads the XML data-fields and parses it, then collects only those data-fields that is defined from the above MySQL table.
- The collected data will be inserted into MySQL DB only when there is change in the state and this state is defined from MySQL table.
Feedback/Suggestions:
- Due to the delay, I am not sure how should I store the configuration in the script which will be shared between each schedules.
- Is there anyway to use
static
variable in the code to store this data? Which will be shared b/w different jobs? or different schedules? - Basically, how should I implement this? A better approach in terms of performance.
Thanks for your time.
UPDATE:
One of the suggestion is to use Java Code as a windows service (?) we could have some common data shared between different jobs? - does it make sense?
Reference:
Java Service Wrapper
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Concurensy 就是答案,尝试创建线程池或执行器服务,并停止某些线程 5 分钟,如果很少有线程使用相同的资源,您甚至可以使用同步。
请记住,并不总是使用的线程越多,完成工作的速度就越快,例如 3 个线程 - 2 分钟
5个线程-6分钟
*阅读有关线程的教程
*创建一些简单的线程并等待5分钟
*阅读一些有关线程池/同步和共享资源的教程(脚本部分)
*测试以找到最佳方法
Concurensy is the answer, try creating Thread pool or Executor servises, and stop certain threads for 5min , you coud even use Synchronization if few threads will be working with the same resource.
Remember not always the more threads use the faster you will finish your job f.e. 3 threads- 2 min
5threads-6 min
*Read tutorial about threads
*create fe simple threads with wait for 5 min
*read some tutorials about thread pool/synchnizations and sharing resourses (script part)
*test to find the most optimal way