We help IT Professionals succeed at work.

when attributeReplaced  will be called ?If attributeReplaced is called on any object Does that mean that House object is not removed from session

chaitu chaitu
on
263 Views
Last Modified: 2010-04-01
I WANT to track memory use of the session object throughout the life of a user's session.  



i have written HttpSessionAttributeListener;say if i am accessing House module and set the object in session
session.setAttribute("House",House) then SessionAttributeListener will be called;when attributeReplaced  will be called?if attributeReplaced is called on House object Does that mean that House object is not removed from session...





public final class SessionAttributeListener implements
          HttpSessionAttributeListener {

     
     public static final String loginStr = "login";

public void attributeAdded(HttpSessionBindingEvent sbe) {
          if (sbe.getName().equals("House")) {
               logger.info(sbe.getSession().getId() +
                         " login added to the session for user: " +
                         sbe.getSession().getAttribute("login").getUserId() +
                         " Time: " + new Date().toString());
          }
     }

     

     public void attributeRemoved(HttpSessionBindingEvent sbe) {
          if (sbe.getName().equals("House")) {
               logger.info(sbe.getSession().getId() +
                         " login removed from the session for user: " +
                         sbe.getSession().getAttribute("login").getUserId() +
                         " Time: " + new Date().toString());
          }
     }

     }

public void attributeReplaced(HttpSessionBindingEvent sbe) {
            if (sbe.getName().equals("House")  ) {
                  logger.info(sbe.getSession().getId()
                              " loginbean modified in the session for user: " +
                              sbe.getSession().getAttribute("loginbean").getUserId() +
                              " Time: " + new Date().toString());
            }
            
      }
Comment
Watch Question

Author

Commented:
logs are coming like this;;      

3921007fce8ca63abd8a1fb4c3e916a8a67d98f099d      1.13E+12            Add      null       House       Attribute Replaced      7.94
3921007fce85b7273b9684144a79ecbbc0572289572      1.13E+12            Add      null       House       Attribute Replaced      7.94

 if attributeReplaced is called on House object Does that mean that House object is not removed from session?
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
chaituu,

         What are you doing?? Just kidding..
         But there is no such thing called  attributeReplaced inside HttpSessionListener interface. So actually it will NEVER be picked up by app server!!

         Look at this:
        http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSessionListener.html

Acton
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Objection here!!

I think that I have answered this question correctly. Please look at my last 2 answers.

chaituu,  Would you agree that I point out your errors?

Acton
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.