开发者

Java patterns for long running process in a web service

开发者 https://www.devze.com 2023-01-10 10:58 出处:网络
I\'m building a web service that executes a database process (SQL code to run several queries , th开发者_运维百科en move data between two really large tables), I\'m assuming some processes might take

I'm building a web service that executes a database process (SQL code to run several queries , th开发者_运维百科en move data between two really large tables), I'm assuming some processes might take 2 to 10 hours to execute.

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)? The process would be executed upon 1 web service call. 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.

Set up a JMS queue and register a listener that takes the message off the queue and persists it.

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. 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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号