java - 测量 session 属性对象的大小

标签 java jsp jakarta-ee servlets httpsession

我想测量对象设置为 HttpSession 时的大小(序列化或非序列化)。我怎样才能做到这一点 ? 即使发现一些支持问题,它也无法使用..有人知道我该怎么做吗?也许, session 监听器的使用可能很有值(value)。但是如何测量对象的大小呢? 例如

session.setAttribute("attrName",sessionObj); 

如何测量这个sessionObj的大小?

最佳答案

您可以使用java.lang.instrument测量物体的大小。

This class provides services needed to instrument Java programming language code. Instrumentation is the addition of byte-codes to methods for the purpose of gathering data to be utilized by tools. Since the changes are purely additive, these tools do not modify application state or behavior. Examples of such benign tools include monitoring agents, profilers, coverage analyzers, and event loggers.

这个answer是如何使用它的示例。

正如您所说,[HttpSessionAttributeListener][3] 是检查添加属性大小的好地方。 在此处添加尺寸代码。

public void attributeAdded(ServletContextAttributeEvent scae) {
    System.out.println("Attribute addedd:["+scae.getName()+"],"+scae.getValue());
}

关于java - 测量 session 属性对象的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21183002/

相关文章:

java - 企业应用程序与普通应用程序

java - JPA/Eclipse链接 : Joined WHERE query does not give expected result

java - Servlet LoginController 的 Servlet.service() 抛出异常 java.lang.ClassNotFoundException : Decoder. BASE64Encoder

java - Android - Activity 中方法的单元测试

java - Jsoup 爬虫和 HTTP 错误获取 URL

java - apache hub - 桌面应用程序

java - 在 Spring MVC 中将子模板包含到模板中的最佳方法

java - Struts 1 - 我的 Web 应用程序未找到 struts-taglib.jar

java - 网页的滚动长度是否有限制?

java - Java SE 中的线程管理模式或包?