Size of objects in HttpSession?

Averrao
2010-03-11
2013-04-25
  • Averrao
    Averrao
    2010-03-11

    Hi,
    (First of all: congratulations for your work, authors!)

    I want to ask you if it is possible to made use of the SizeOf methods without the need of passing the jar through javaagent runtime option. (My WAS 6.1 is unable to handle the MANIFEST.MF file. I don’t know if it has to be with the ‘Premain-Class’ entry ¿?).

    I just want to know the size of objects in my HttpSession. So, it’s possible to initialize something in the init() method of a servlet?

    public class SessionMeasurer extends HttpServlet {
        public void init() {
            // PENDIENTE
            // ... some stuff with SizeOf facility here ¿? ...
        }
        public void doGet (HttpServletRequest request,
                HttpServletResponse response) {
            HttpSession session = request.getSession(false);
            String attributeName = "";
            Object attributeValue = null;
            for (Enumeration<?> attributeNames = session.getAttributeNames(); attributeNames
                    .hasMoreElements();) {
                attributeName = (String) attributeNames.nextElement();
                attributeValue = session.getAttribute(attributeName);
                System.out.println(attributeName);
                System.out.println(SizeOf.humanReadable(SizeOf.deepSizeOf(attributeValue)));
            }
        }
    }
    

    Thanks!