简体   繁体   English

Java模式,可在Web服务中长时间运行

[英]Java patterns for long running process in a web service

I'm building a web service that executes a database process (SQL code to run several queries , then move data between two really large tables), I'm assuming some processes might take 2 to 10 hours to execute. 我正在构建一个执行数据库进程的Web服务(SQL代码运行多个查询,然后在两个非常大的表之间移动数据),我假设某些进程可能需要2到10个小时才能执行。

What are the best practices for executing a long running database process from within a Java web service (it's actually REST-based using JAX-RS and Spring)? 从Java Web服务(它实际上是使用JAX-RS和Spring的基于REST的)中执行长时间运行的数据库过程的最佳实践是什么? The process would be executed upon 1 web service call. 该过程将在1个Web服务调用后执行。 It is expected that this execution would be done once a week. 预计该执行将每周执行一次。

Thanks in advance! 提前致谢!

It's gotta be asynchronous. 它必须是异步的。

Since your web service call is an RPC, best to have the implementation validate the request, put it on a queue for processing, and immediately send back a response that has a token or URL to check on progress. 由于您的Web服务调用是RPC,因此最好让实现对请求进行验证,将其放在队列中进行处理,然后立即发回带有令牌或URL的响应以检查进度。

Set up a JMS queue and register a listener that takes the message off the queue and persists it. 设置一个JMS队列并注册一个侦听器,该侦听器将消息从队列中移出并保留它。

If this is really taking 2-10 hours, I'd recommend looking at your schema and queries to see if you can speed it up. 如果确实需要2到10个小时,则建议您查看您的架构和查询,看看是否可以加快速度。 There's an index missing somewhere, I'd bet. 我敢打赌,某处缺少索引。

Where I work, I am currently evaluating different strategies for this exact situation, only times are different. 在我工作的地方,我目前正在针对这种确切情况评估不同的策略,只是时间有所不同。

With the times you state, you may be better served by using Publish/Subscribe message queuing ( ActiveMQ ). 随着时间的推移,使用“发布/订阅”消息队列( ActiveMQ )可能会为您提供更好的服务。

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

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