简体   繁体   English

Struts 2中的Java应用程序可以管理多少个会话?

[英]How many sessions can be managed by an Java Application in Struts 2?

I am working on Transaction Management application, and I am using Struts2. 我正在使用事务管理应用程序,并且正在使用Struts2。 I have used internally a session for setting and getting values like 我在内部使用了一个会话来设置和获取诸如

ActionContext.getContext().getSession().put("string", string);

Is there any limit or any disadvantage of using a session like this in the application? 在应用程序中使用这样的会话是否有任何限制或缺点?

Limit is the size of your computers physical memory.you dont store dynamic values in session because someone can modify them in the meanwhile , so store only those values in session which represent any user specific data or static values (ie which are not going to be changed while session exists). 限制是计算机物理内存的大小。您不将动态值存储在会话中,因为同时有人可以对其进行修改,因此,请仅在会话中存储表示任何用户特定数据或静态值的值(即不会存储任何值)。会话存在时更改)。

Note : static here is not static keyword . 注意:这里的static不是static关键字。

There's no limit. 没有限制 The session in Struts 2 is implemented as a Map to simplify access to servlet session's attributes. Struts 2中的会话被实现为Map以简化对Servlet会话属性的访问。

I have written in this answer: 我写了这个答案:

The SessionMap is specifically designed for the purposes if you want to have access to the servlet session attributes. 如果您想访问Servlet会话属性,则SessionMap是专门为此目的而设计的。 So, the user is able to keep a synchronized collection of objects in session and use it instead of HttpSession directly. 因此,用户能够在会话中保留对象的同步集合,并直接使用它代替HttpSession

I know only one disadvantage if you get the session from the action context, it might return null . 我只知道一个缺点,如果您从操作上下文获取会话,则它可能会返回null The solution is in this answer. 解决的办法就是这个答案。

There are two methods to obtain a session map to the action: 有两种方法可获取操作的会话映射:

  1. Implement SessionAware . 实现SessionAware By default the session map is populated on action call. 默认情况下,在操作调用中填充会话映射。 This is a preferable way. 这是一种更好的方法。
  2. Get a session map from the action context. 从操作上下文获取会话映射。 This way you should make sure the request is handled by the Struts2 filter. 这样,您应该确保请求由Struts2过滤器处理。

The first method is preferred , as explained in the docs page, allows you use a session in tests. 如docs页面中所述, 首选第一种方法,它允许您在测试中使用会话。

It's your size of the internal/physical memory of the system. 它是您系统内部/物理内存的大小。 The session is create a singleton class in your war file.The war file is stored in your Server. 该会话是在war文件中创建一个单例类.war文件存储在您的服务器中。 The server is in your C: folder in windows. 服务器位于Windows的C:文件夹中。 So the session is depends on your physical memory. 因此,会话取决于您的物理内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM