停止服务器请求
我有一个网络应用程序(java,tomcat),允许用户通过水晶报告生成报告。问题是,如果用户请求需要几个小时才能完成的庞大报告,我的整个应用程序就会停止运行。有没有办法停止这样的请求,比如说 5 分钟后它还没有完成?除了优化速度和限制报告大小之外,还有其他解决方法吗?
I have a web app (java, tomcat) that allows users to generate reports through crystal reports. Problem is if a user requests a huge report that takes hours to complete, my whole app grinds to a halt. Is there a way to stop a request like this, say if after 5 minutes it has not been complete? Other than optimizing for speed and limiting report sizes, are there any other work-arounds?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您没有在另一个线程中运行报告生成。最好在另一个线程中运行报告生成,并在准备就绪时将链接发送回用户。
您可以使用java的ExecutorService并为线程设置一些超时,如果它花费的时间超过您为其分配的时间,则该线程将过期。
搜索Java ExecutorService、Future、Callable教程
示例代码:
I think you are not running your report generation in another Thread. It is better to run the report generation in another Thread and send a link back to user when it is ready.
You can use ExecutorService of java and set some timeout for the thread and it will expire if it takes more than the time you have allocated for it.
Search for Java ExecutorService, Future, Callable tutorial
Sample code:
另一种方法是在单独的线程中运行报告生成(或者可能使用ExecutorService),并在生成时间超过某个阈值时调用Thread.interrupt()。如果线程当前在 I/O(网络、数据库)上阻塞,则该线程很可能会被中断。
Another approach is to run report generation in a separate thread (or maybe using
ExecutorService
) and callThread.interrupt()
when generation time exceeds some threshold. Chances are the thread will be interrupted if it currently blocks on I/O (network, database).