| From | Sent On | Attachments |
|---|---|---|
| Felipe Schnack | Dec 17, 2002 1:11 pm | |
| Mike W-M | Dec 17, 2002 6:17 pm | |
| Felipe Schnack | Dec 18, 2002 3:11 am | |
| Mike W-M | Dec 18, 2002 3:28 am | |
| Mike W-M | Dec 18, 2002 3:32 am | |
| Felipe Schnack | Dec 18, 2002 4:49 am | |
| Craig R. McClanahan | Dec 18, 2002 9:48 am | |
| Felipe Schnack | Dec 18, 2002 9:50 am | |
| Andrew Milkowski | Dec 18, 2002 10:02 am | |
| Bill Barker | Dec 18, 2002 9:53 pm |
| Subject: | Re: HttpSession issues | |
|---|---|---|
| From: | Craig R. McClanahan (crai...@apache.org) | |
| Date: | Dec 18, 2002 9:48:42 am | |
| List: | org.apache.tomcat.users | |
On 18 Dec 2002, Felipe Schnack wrote:
Date: 18 Dec 2002 09:12:20 -0200 From: Felipe Schnack <feli...@ritterdosreis.br> Reply-To: Tomcat Users List <tomc...@jakarta.apache.org> To: Tomcat Users List <tomc...@jakarta.apache.org> Subject: Re: HttpSession issues
Yes, but this is related to an user session. How is possible to have concurrent updates on an user session when an user have only one browser window open and does a refresh?
Here's at least two very simple ways:
* Use frames (the requests for each frame will happen simultaneously yet belong to the same session)
* User presses REFRESH before the previous request has completed. (Same thing could happen if you're using a meta refresh tag to automatically refresh).
In either case, your session will be processed by more than one request at the same time (on different request processing threads), so anything you store in the session needs to be thread safe.
This iteration is done in a taglib. And why this only happens when he refreshes the pages, but not when he hits enter in the url bar? BTW, inside this loop in some circumstances I change the session attributes. In other words, the code look like this:
Enumeration attrs = session.getAttributeNames(); while(attrs.hasMoreElements()) { String name = (String)attrs.nextElement(); Object value = session.getAttribute(name); if (<some weird conditions>) { session.removeAttribute(name); } }
This removeAttribute() is the problem?
Yes. And it's not a thread safety issue.
You are modifying the collection (i.e. the internal HashMap of session attributes) that you are enumerating over. Such behavior does not need to be supported by a java collections class.
The safe way to do this is accumulate a separate list of just the session keys you want to remove, then run a separate iteration over those keys and call session.removeAttribute().
Craig





