在数据库更新期间防止会话超时 [英] Prevent session timeout during database update

查看:146
本文介绍了在数据库更新期间防止会话超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Web应用程序调用存储过程以执行密集型数据库更新。 web.xml 的相关部分已更新为四小时:

A web application calls a stored procedure to perform an intensive database update. The relevant portion of web.xml was updated to four hours:

<session-config>
    <session-timeout>240</session-timeout>
</session-config>

解决方案可用的技术包括Java 1.4.2,Struts 2,Tomcat 5.5和Apache commons 。大多数其他技术(例如jQuery)是不允许的。

The technologies available for the solution include Java 1.4.2, Struts 2, Tomcat 5.5, and Apache commons. Most other technologies (such as jQuery) are not permitted.

更新大约需要一个小时然而,运行时,配置值为4小时是违反公司标准的(有充分理由)。生产中不允许四小时超时配置。

The update takes about an hour to run, however a configuration value of four hours is against corporate standards (for good reason). A four hour timeout configuration is not permitted in production.

什么将确保请求不会数据库更新执行时超时?

What will ensure that the request does not time out while the database update executes?

我对前两种情况的关注是产生的进程最终将被Servlet容器杀死。

My concern in the first two cases is that the spawned process will eventually be killed by Servlet container.


  1. Spawn the数据库更新过程作为后台任务。

  2. 让Servlet不断刷新页面以检查完成情况。



JavaScript Ping



JavaScript Ping


  1. 将数据库更新过程作为后台任务生成。

  2. 有JavaScript代码ping服务器一段时间。

类似于在JSF中长时间处理期间防止会话超时,但没有jQuery。

Similar to Preventing session timeout during long processing time in JSF, but without jQuery.

编写一个侦听请求的简单服务器:

Write a simple server that listens for requests:


  1. Servlet向监听器发送请求。

  2. 监听器运行更新。

由于服务器独立于Tomcat运行,因此不会发生会话超时。数据库更新将运行完成而不会被终止。这有很多问题(错误处理不是我最关心的问题),可能是最后的选择。

Since the server runs independently of Tomcat, the session timeout cannot occur. The database update will run to completion without being killed. This has numerous issues (error handling not the least of my concern) and is likely the option of last resort.

优化查询以在30分钟内完成(允许的最大超时时间),但很可能无法充分优化查询。

Optimizing the query to finish in under 30 minutes (the maximum permitted timeout) is possible, but it is likely the query cannot be optimized sufficiently.

不幸的是,升级数据库硬件不是一种选择。

Upgrading the database hardware is not an option, unfortunately.

非常感谢!

推荐答案

在我看来,没有用户会想坐在屏幕前监视后台工作4个小时。几年前,我不得不实施耗时数小时的报告生成。实现的解决方案如下:

In my opinion, no user would want to sit in front of screen monitoring a background job for 4 hours. Few years ago, I had to implement report generation which took hours. the implemented solution was the following:


  • 在后台线程中生成报告。通过应用程序上下文列表监视并提供该线程。该线程包含有关所有者及其进度的信息。

  • 用户可以列出自己的线程并查看进度。

  • 完成后,报告线程将存储离线访问报告,向所有者发送电子邮件通知,其中包含下载生成的报告的链接。

这篇关于在数据库更新期间防止会话超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆