我想测量对象设置为 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/