RE: Clear user session

2003-06-09 Thread Phillip Qin
Is this a re-post? I saw some pal posted a very good explaination why you
cann't do it. Are you not reading those posts?.

My suggestion is to use session.removeAttribute(attr_name) or simply set
those attributes to null.

-Original Message-
From: shyam [mailto:[EMAIL PROTECTED] 
Sent: June 6, 2003 2:40 PM
To: Tomcat Users List
Subject: 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Clear user session

2003-06-08 Thread Yoav Shapira
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
[EMAIL PROTECTED]

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

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: clear user session

2003-06-06 Thread Phillip Qin
Simple set the element value to null instead of removing it.

-Original Message-
From: Shyama Gavulla [mailto:[EMAIL PROTECTED] 
Sent: June 6, 2003 3:28 PM
To: [EMAIL PROTECTED]
Subject: Re: clear user session


-- 

Hi,
Thanks for the reply. As you have said I was trying to make changes while
iterating over the loop. I cant do session.invalidate as I want the session
to be valid but certain keys to be removed. I am using tomcat 4.1 and the
same code in Jrun works fine . No errors. I wonder how that works fine.
Anyways I have a fix for that . I am trying to implement it . Thanks a lot

Shyam
- Original Message - 
From: "Tim Funk" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Friday, June 06, 2003 3:19 PM
Subject: Re: Clear User Session


> Depending on who you talk to its a bug or not a bug in tomcat.
>
> session.getAttributeNames() returns an Enumeration. Under the covers, the
> Enumeration is actually a facade around an Iterator. Iterators are
fail-fast
> so if you are enumerating through session attributes and make changes, you
> get the error as you have described.
>
> The arguement is: is  Enumeration allowed to be fail-fast?
>
> In the meantime, 4.1 and 5 were patched to not make the Enumerator
> originating from session.getAttributeNames be fail-fast.
>
>
> As an aside - if you need to clear out a session: session.invalidate() is
> much easier.
>
> -Tim
>
> Shyama Gavulla wrote:
>  > 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: clear user session

2003-06-06 Thread Shyama Gavulla

-- 

Hi,
Thanks for the reply. As you have said I was trying to make changes while
iterating over the loop. I cant do session.invalidate as I want the session
to be valid but certain keys to be removed. I am using tomcat 4.1 and the
same code in Jrun works fine . No errors. I wonder how that works fine.
Anyways I have a fix for that . I am trying to implement it . Thanks a lot

Shyam
- Original Message - 
From: "Tim Funk" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <[EMAIL PROTECTED]>
Sent: Friday, June 06, 2003 3:19 PM
Subject: Re: Clear User Session


> Depending on who you talk to its a bug or not a bug in tomcat.
>
> session.getAttributeNames() returns an Enumeration. Under the covers, the
> Enumeration is actually a facade around an Iterator. Iterators are
fail-fast
> so if you are enumerating through session attributes and make changes, you
> get the error as you have described.
>
> The arguement is: is  Enumeration allowed to be fail-fast?
>
> In the meantime, 4.1 and 5 were patched to not make the Enumerator
> originating from session.getAttributeNames be fail-fast.
>
>
> As an aside - if you need to clear out a session: session.invalidate() is
> much easier.
>
> -Tim
>
> Shyama Gavulla wrote:
>  > 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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Clear User Session

2003-06-06 Thread Tim Funk
Depending on who you talk to its a bug or not a bug in tomcat.

session.getAttributeNames() returns an Enumeration. Under the covers, the 
Enumeration is actually a facade around an Iterator. Iterators are fail-fast 
so if you are enumerating through session attributes and make changes, you 
get the error as you have described.

The arguement is: is  Enumeration allowed to be fail-fast?

In the meantime, 4.1 and 5 were patched to not make the Enumerator 
originating from session.getAttributeNames be fail-fast.

As an aside - if you need to clear out a session: session.invalidate() is 
much easier.

-Tim

Shyama Gavulla wrote:
> 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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]