Wicket:如何在会话内同步请求
场景:基于 Apache Wicket 的 Web 应用程序在 Tomcat 服务器上运行。
用户在浏览器中打开 URL,创建会话并在浏览器中显示简单的主页,用户单击按钮并调用 AJAX 调用。应用程序获取请求并做一些准备响应的事情。同时,浏览器中的用户或 JavaScript 调用另一个 AJAX 调用——第二个请求在应用程序中的另一个线程中处理,因为应用程序的大部分部分是特定于会话的并且不是线程安全的(因为一名用户 = 一次会话),异常抛出。
可能的解决方案:
使所有应用程序类线程安全(成本非常高)
调整 GUI,这样就不会在一个会话中同时运行两个 AJAX 调用(不可能由于浏览器 GUI 的性质)
在 Wicket 或 Tomcat 级别上同步一个会话中的所有请求(但是如何?)
另一种实践或技术???
谢谢
Scenario: Apache Wicket based web application running on Tomcat server.
User opens URL in browser, session is created and simple main page is shown in browser, user clicks on button and AJAX call is invoked. Application gets request and doing some stuff preparing response. In same time user or JavaScript in browser invokes another AJAX call -- this second requests is processed in another thread in application, and because most parts of application are session specific and aren't thread-safe (because one user = one session), exception throws.
Possible solutions:
make all application classes thread-safe (very costly)
adapt GUI so no simultaneously runs two AJAX calls in one session (not possible due nature of browser GUI)
synchronize all requests in one session on Wicket or Tomcat level (but how?)
another practice or technique ???
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对同一 PageMap 中的页面或组件的请求
单个会话已经是同步的——一次只有一个线程。请求资源,例如
图像、javascript、css 文件等都是异步处理的。 (不同客户
永远不会互相阻塞,因为每个客户端都有自己的 Session 和 PageMap)。
但是,我认为,对会话本身中的项目的访问并未显式同步。
顺便说一句,从不是请求线程的线程访问会话/页面并不是一个好主意,因为容器可以在请求之间自由地对会话/页面执行任何操作 - 例如将其写入磁盘等。
Requests to pages or components within the same PageMap in
a single Session are already synchronous - only one thread at a time. Requests for resources like
images, javascript, css files etc. are handled asynchronously. (Different clients
never block each other as each client has its own Session and PageMap).
However, access to items in the Session itself, I believe, are not explicitly synchronized.
Incidentally, accessing the Session/Pages from a thread which is not a Request Thread is not a good idea, as the container is free to do anything with your Session/Page between requests - e.g. write it out to disk etc.
抛出的异常是什么?如果抛出异常,那么我会假设 Session 对象的一个关键部分需要同步或更加小心地处理,而不是整个会话。
我没有理由充分利用它们,但我知道 wicket-ajax.js 中有一些通道(在 org.apache.wicket.ajax 包中找到)。这些控制如何处理多个 AJAX 调用。他们可能值得一看。该文件中有以下注释:
What is the exception that is thrown? If an exception is thrown then I would assume that there is a critical section of the Session object that needs to be synchronized or handled with more care and maybe not the entire session.
I have not had reason to utilize them much, but I know there are channels as part of the wicket-ajax.js (found in org.apache.wicket.ajax package). These control how multiple AJAX calls are handled. They might be worth a look. In this file is the following comment: