执行方法而不阻塞客户端
我正在使用 Java 来创建 Web 应用程序。 应用程序必须加载一个表单,该表单将其数据发送到调用长业务逻辑的 jsp。 我需要 jsp 返回一条消息,例如“感谢您使用我的服务,过程完成后将向您发送一封电子邮件”。
问题是,如果我写这样的东西:
<html>
<head></head>
<body>
...
<span>thank you for using my service, an email will sent to you when the proccess is done</span>
...
<% businessClass.doLongOperation(); %>
...
...
</Body>
</html>
jsp将运行很长时间,用户将不得不等待操作结束。 此外,如果用户关闭浏览器,我不确定jsp是否会继续其工作。
如何将长操作与jsp隔离,以便用户不必等待所有执行时间,以及如何使长操作执行不依赖于浏览器?
纳尔
I am using Java in order to create web application.
The application has to load a form which is sent it's data to a jsp that call a long business logic.
I need that the jsp will return a message like "thank you for using my service, an email will sent to you when the proccess is done."
The problem is that if I will write something like:
<html>
<head></head>
<body>
...
<span>thank you for using my service, an email will sent to you when the proccess is done</span>
...
<% businessClass.doLongOperation(); %>
...
...
</Body>
</html>
the jsp will run for long time and the user will have to wait for the operation to end. Moreover, i f the user will close the browser, I am not sure if the jsp will continue its job.
How can I isolate the long operation from the jsp so the user will not have to wait all the execution time and also how can I make the long operation execution not to be depend on the browser?
Naor
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 JSP 可能在服务器端由 servlet 或 Struts Action 或 Spring MVC 控制器支持。
在该对象中,执行异步执行:
其中
executor
是java.util.concurrent.Executor
。Your JSP is probably backed on the server side by a servlet or Struts Action or Spring MVC Controller.
In that object, peform an asynchronous execution:
Where the
executor
is an instance ofjava.util.concurrent.Executor
.