Java的:通过单击弹簧web应用按钮取消正在运行的进程(或任务)弹簧、单击、按钮、正在运行

2023-09-11 22:35:32 作者:三个字软妹 少女心的三个字

我提交了我的web应用程序的请求可能需要很长时间来处理请求并得到响应。有什么办法,用户可以通过单击Web应用程序按钮,取消中间的请求。

I submitted a request in my web application which may take long time to process the request and get response. Is there any way user can cancel the request in the middle by clicking a button in the web application.

中止Ajax请求将不会停止在服务器端的请求。

Aborting the ajax request will not stop the request in the server side.

有什么办法来实现这一目标?

Is there any way to achieve this?

推荐答案

为什么用户要取消一个请求?

Why would a user want to cancel a request?

如果是长时间运行的,他们不希望等待一个更好的想法可能是使异步进程。返回收据令牌用户立即让他们知道他们可以稍后再回来与他们的收据回暖的结果。提供,取入令牌,并返回响应的第二方法

If it's long running, and they don't want to wait, a better idea might be to make it an asynchronous process. Return a receipt token to the user immediately and let them know they can come back later with their receipt to pick up the result. Provide a second method that takes in the token and returns the response.

更新:

您需要研究,看看你的数据库服务器有一个API,允许您取消一个过程。这是这里的关键。如果没有,你的运气了。我不知道有任何这样的事情在JDBC API中,因此即使它你就必须想出一个办法来获取命令到数据库。

You need to research to see if your database server has an API to allow you to cancel a process. That's the key thing here. If it doesn't you are out of luck. I'm not aware of any such thing in the JDBC API, so even if it does you'll have to figure out a way to get that command to the database.