如何将方法转换为异步 - Spring、DWR?

How to convert a method to async - Spring, DWR?

目前正在开发 Web 应用程序。此应用程序的一个特定 area/page 执行特定时间的数据库操作。本页当前结构为:

1) DWR call from the front end to the backend
2) Front end waits for the backend to return data
3) When data is returned, the callback function is executed in the 
   front end and data is displayed to user in the format needed.

在第 2 步中,后端需要花费大量时间来处理和发回数据。在此期间,应用程序无法使用。

应该做的改变是:

1) Let the user use the application after sending the request in step #1
2) Front end will be populated with data after the backend processes the data and 
   send the details back.
3) When user revisits the page, information from previous request is available.

我正在寻找使这成为可能的方法。不确定是否有 DWR 或 Spring 机制来实现此目的。请指出正确的方向,以便我可以研究更多所需的正确代码。

主要问题是 - 您对页面使用的技术是什么,需要多少 "wait"。

  1. 最简单的情况是浏览器可以在等待期间保持打开的连接:这种情况发生在等待时间不太长且用户保持在同一页面上的情况下。在这种情况下,服务器公开 REST 而不知道谁在使用它。大部分工作将在需要执行异步 ajax 的客户端进行 - 如果它是 DWR see here , if it's spring then it doesn't meddle on the client side and you can use any javascript helpers you like, e.g. JQuery

  2. 如果等待时间长,或者即使用户同时导航到另一个页面也应该收到 'push' 通知,情况会变得更加复杂。在那种情况下,我建议研究 websockets or server-sent events 或长轮询机制(google 它 - 有很多示例和产品,有些是免费的,有些是昂贵的)。无论如何,请做好学习曲线的准备。

  3. 关于要求 3(重新访问页面时快速查看数据的方法),我没有任何神奇的解决方案,只有良好的旧缓存...您的缓存可以找到在不同的位置——通过中间的一些缓存代理从客户端到服务器。显然需要考虑缓存刷新策略——最简单的情况是您是否可以使用相同的数据"for X minutes/hours",复杂的情况是您需要刷新特定的业务操作。