numberOfViewsInSession 和多个选项卡的问题

发布于 2024-10-09 14:47:30 字数 3353 浏览 5 评论 0原文

我的应用程序和内存有一个大问题。该应用程序(java 与 jsf/richfaces/facelet)同时被大约 7000 个用户使用。

默认情况下,变量 com.sun.faces.numberOfViewsInSession 在 web.xml 中设置为 15。该变量创建视图树,并且 jsf 在向后单击 15 次期间检索特定视图。

例如,我的应用程序有 3 个屏幕,并且我使用 Firefox。我进入第一个选项卡中的第三个屏幕。在第二个选项卡中,我有第一个屏幕,我单击下一个按钮,jsf 检索第一个屏幕并转到第二个屏幕。

这个机制很棒,但它消耗大量内存(对我来说,每个会话消耗 25Mo),当你将这个数字乘以 7000 时,我需要 175 Go 内存,这是不可能的。

所以我尝试将 com.sun.faces.numberOfViewsInSession 设置为 1(按会话 3Mo)。

但在我的示例中,当我单击下一个按钮上的第二个选项卡时,我收到下一个错误:

javax.servlet.ServletException: viewId:/private/pages/data/dataView.faces - View /private/pages/data/dataView.faces could not be restored.
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:270)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at fr.generali.mezzo.front.commun.performance.filters.PerformanceFilter.doFilter(PerformanceFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:420)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)

此错误是合乎逻辑的,因为我的 numberOfViewsInSession 是 1。

所以,我的问题是:

鉴于我知道视图中的数据(例如第二个选项卡),我该如何捕获异常并为我的用户创建新视图?

感谢您的帮助。

I have a big problem with my application and the memory. The application (java with jsf/richfaces/facelet) is used by some 7000 users simultaneously.

By default, the variable com.sun.faces.numberOfViewsInSession is set to 15 in the web.xml. This variable create a tree of views and jsf retrieve a specific view during 15 click backwards.

For example, I have 3 screens for an application and I use firefox. I go in third screen in a first tab. In a second tab, I have the first screen and I click on the next button, jsf retrieve the first screen and go to the second.

This mechanism is great but it consumes a lot of memory (25Mo by session for me) and when you multipy this number by 7000, I need 175 Go of memory, it's impossible.

So I tried to set com.sun.faces.numberOfViewsInSession equal to 1 (3Mo by session).

But with my example, when I click in the second tab on the next button I get the next error:

javax.servlet.ServletException: viewId:/private/pages/data/dataView.faces - View /private/pages/data/dataView.faces could not be restored.
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:270)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at fr.generali.mezzo.front.commun.performance.filters.PerformanceFilter.doFilter(PerformanceFilter.java:72)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:173)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
at org.apache.catalina.authenticator.SingleSignOn.invoke(SingleSignOn.java:420)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)

This error is logical because my numberOfViewsInSession is 1.

So, my question is:

Given that I know data which are in the view (for the second tab), how can I do to catch the exception and create a new view for my user ?

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫烠⑼条掵仅有一顆心 2024-10-16 14:47:30

通过利用您对应用程序的特定知识来手动恢复视图对于胆小的人来说可能不是一项任务。

如果您想遵循该路径,我认为您不应该尝试捕获异常,而应该利用 JSF 中的 StateManager API。这允许您自定义 JSF 框架管理其视图状态的方式。

请注意,这是一个高级主题。或者用 Ed Burns(JSF 规范负责人)的话来说:

视图状态管理是一项复杂的业务,很少有应用程序开发人员需要担心对其进行自定义。

也就是说,如果您尚未使用 JSF 2.0,那么我强烈建议您升级到此版本。 JSF 2.0 中的一个重要新功能是部分状态保存。这极大地减少了存储状态所需的内存量。

还有另一种选择,我想您可能已经考虑过看到您了解诸如 com.sun.faces.numberOfViewsInSession 之类的参数,即在客户端上使用状态。这将视图状态存储在隐藏字段中,并且基本上为您提供了无限的内存,因为客户端用作分布式内存。当然,这是以增加网络开销为代价的。对于 AJAX,这种开销可能会非常大,以至于无法考虑。

Restoring the view manually by exploiting the specific knowledge you have about your application is maybe not a task for the faint-hearted.

If you would like to follow that path, I think you should not attempt to catch the exception, but to take advantage of the StateManager API in JSF. This allows you to customize the way how the JSF framework manages its view state.

Do note that this is an advanced topic. Or in Ed Burns' (JSF spec lead) words:

View state management is a complex business, and few application developers will have to worry about customizing it.

That said, if you're not already using JSF 2.0, then I highly recommend upgrading to this. A big new feature in JSF 2.0 is Partial State Saving. This dramatically reduces the amount of memory needed to store state.

Yet another option, which I guess you might have already considered seeing you have knowledge of parameters like com.sun.faces.numberOfViewsInSession is using state on client. This stores the view state in hidden fields, and basically given you an unlimited memory since the client is used as distributed memory. Of course this comes at the expensive of increased network overhead. In case of AJAX this overhead might be so large that it's impossible to consider.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文