You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by shyam <sh...@adamshand.net> on 2003/06/06 20:39:49 UTC

Clear user session

Hi All,

I just moved my webapp from jrun to tomcat. I have a method which clears the
user session. The code snippet is

 Enumeration session_var = session.getAttributeNames();

     while(session_var.hasMoreElements())
     {
         String key=(String)session_var.nextElement();

I am getting an error here and the exception is

java.util.ConcurrentModificationException at
java.util.HashMap$HashIterator.nextEntry

How can I resolve this error.

Thanks a lot in advance
shyam



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Clear user session

Posted by Yoav Shapira <yo...@yahoo.com>.
Howdy,
Something else is modifying the session (adding/removing attributes or
otherwise modifying the backing collection of your session_var enumeration)
while you're iterating through it.

>      while(session_var.hasMoreElements())
>      {
>          String key=(String)session_var.nextElement();

You need to make the above code synchronized on the session.  This may not be
as trivial as it sounds: for example, it might be impossible if your
environment is clustered.

Alternative options include doing this on session passivation or destruction
(probably the former), using the appopriate listener.  

Why are you clearing all the attributes instead of a specific one?  

Yoav Shapira


=====
Yoav Shapira
yoavs@computer.org

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org