Re: HttpSession issues

2002-12-18 Thread Felipe Schnack
  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? 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?

On Wed, 2002-12-18 at 00:18, Mike W-M wrote:
 This is nothing in particular to do with Tomcat, more with multi-threaded
 programming.
 The exception is used to indicate that whatever you've started iterating
 through has been changed in the meantime.
 The likely scenario here is that some other request is running at the same
 time as you're doing your looping and it's adding or deleting a session
 attribute.  Check the java.util javadocs for more info.
 
 I think the solution will be to synchronise the enumerating block of code,
 and all other blocks that modify the session attributes, on the session
 object.  It's generally good practice to minimise the amount of code that
 needs to be synchronised (and the time it takes) for performance reasons.
 
 Mike.
 
 
 - Original Message -
 From: Felipe Schnack [EMAIL PROTECTED]
 To: Tomcat Users List [EMAIL PROTECTED]
 Sent: Tuesday, December 17, 2002 9:12 PM
 Subject: HttpSession issues
 
 
   There's something problematic about the Enumeration i get from
 HttpSession.getAttributeNames?
   I have some situations in my application that I have to loop thru all
 my session attributes, but for some reason sometimes I get an
 java.util.ConcurrentModificationException then looping them...
   The strangest thing is that a developer here get this error when he
 reloads a page, but it doesn't happen when he press enter in the URL
 bar... and this JSP file isn't the target of an HTML form... but
 receives parameters from the query string
   I'm using JDK 1.4.1 and Tomcat 4.1.12
 
 --
 
 Felipe Schnack
 Analista de Sistemas
 [EMAIL PROTECTED]
 Cel.: (51)91287530
 Linux Counter #281893
 
 Faculdade Ritter dos Reis
 www.ritterdosreis.br
 [EMAIL PROTECTED]
 Fone/Fax.: (51)32303328
 
 
 --
 To unsubscribe, e-mail:
 mailto:[EMAIL PROTECTED]
 For additional commands, e-mail:
 mailto:[EMAIL PROTECTED]
 
 
 
 
 --
 To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
 For additional commands, e-mail: mailto:[EMAIL PROTECTED]
 
-- 

Felipe Schnack
Analista de Sistemas
[EMAIL PROTECTED]
Cel.: (51)91287530
Linux Counter #281893

Faculdade Ritter dos Reis
www.ritterdosreis.br
[EMAIL PROTECTED]
Fone/Fax.: (51)32303328


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




Re: HttpSession issues

2002-12-18 Thread Mike W-M
Yep, that's the problem!
Try keeping a list of the names that you want to remove until you've
finished iterating the loop, then remove them all at once?

Mike
- Original Message -
From: Felipe Schnack [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Wednesday, December 18, 2002 11:12 AM
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? 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?




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




Re: HttpSession issues

2002-12-18 Thread Mike W-M
Also (but not related to your problem) I think I noticed just the other day
that hitting return in the address bar isn't the same as hitting refresh,
because the browser can serve the page from the cache.
For what it's worth, you can have concurrent requests if they hit refresh
twice in quick succession (the browser just ignores the response to the
first one, I think).

Mike


- Original Message -
From: Felipe Schnack [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Wednesday, December 18, 2002 11:12 AM
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? 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?

On Wed, 2002-12-18 at 00:18, Mike W-M wrote:
 This is nothing in particular to do with Tomcat, more with multi-threaded
 programming.
 The exception is used to indicate that whatever you've started iterating
 through has been changed in the meantime.
 The likely scenario here is that some other request is running at the same
 time as you're doing your looping and it's adding or deleting a session
 attribute.  Check the java.util javadocs for more info.

 I think the solution will be to synchronise the enumerating block of code,
 and all other blocks that modify the session attributes, on the session
 object.  It's generally good practice to minimise the amount of code that
 needs to be synchronised (and the time it takes) for performance reasons.

 Mike.


 - Original Message -
 From: Felipe Schnack [EMAIL PROTECTED]
 To: Tomcat Users List [EMAIL PROTECTED]
 Sent: Tuesday, December 17, 2002 9:12 PM
 Subject: HttpSession issues


   There's something problematic about the Enumeration i get from
 HttpSession.getAttributeNames?
   I have some situations in my application that I have to loop thru all
 my session attributes, but for some reason sometimes I get an
 java.util.ConcurrentModificationException then looping them...
   The strangest thing is that a developer here get this error when he
 reloads a page, but it doesn't happen when he press enter in the URL
 bar... and this JSP file isn't the target of an HTML form... but
 receives parameters from the query string
   I'm using JDK 1.4.1 and Tomcat 4.1.12

 --

 Felipe Schnack
 Analista de Sistemas
 [EMAIL PROTECTED]
 Cel.: (51)91287530
 Linux Counter #281893

 Faculdade Ritter dos Reis
 www.ritterdosreis.br
 [EMAIL PROTECTED]
 Fone/Fax.: (51)32303328


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




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

--

Felipe Schnack
Analista de Sistemas
[EMAIL PROTECTED]
Cel.: (51)91287530
Linux Counter #281893

Faculdade Ritter dos Reis
www.ritterdosreis.br
[EMAIL PROTECTED]
Fone/Fax.: (51)32303328


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




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




Re: HttpSession issues

2002-12-18 Thread Felipe Schnack
  Ok, thanks a lot!
On Wed, 2002-12-18 at 09:29, Mike W-M wrote:
 Yep, that's the problem!
 Try keeping a list of the names that you want to remove until you've
 finished iterating the loop, then remove them all at once?
 
 Mike
 - Original Message -
 From: Felipe Schnack [EMAIL PROTECTED]
 To: Tomcat Users List [EMAIL PROTECTED]
 Sent: Wednesday, December 18, 2002 11:12 AM
 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? 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?
 
 
 
 
 --
 To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
 For additional commands, e-mail: mailto:[EMAIL PROTECTED]
 
-- 

Felipe Schnack
Analista de Sistemas
[EMAIL PROTECTED]
Cel.: (51)91287530
Linux Counter #281893

Faculdade Ritter dos Reis
www.ritterdosreis.br
[EMAIL PROTECTED]
Fone/Fax.: (51)32303328


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




Re: HttpSession issues

2002-12-18 Thread Craig R. McClanahan


On 18 Dec 2002, Felipe Schnack wrote:

 Date: 18 Dec 2002 09:12:20 -0200
 From: Felipe Schnack [EMAIL PROTECTED]
 Reply-To: Tomcat Users List [EMAIL PROTECTED]
 To: Tomcat Users List [EMAIL PROTECTED]
 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


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




Re: HttpSession issues

2002-12-18 Thread Felipe Schnack
  The strange thing about the error is that the programmer isn't using
any frame, or reloading before the previous request ended (it's a local
connection, it's pretty fast..) Anyway, at least we found a bug 
  I did this approach of store the desired key names... in an Vectory,
it looks ugly, but it seems it works :-)
  Thank you all!

On Wed, 2002-12-18 at 15:49, Craig R. McClanahan wrote:
 
 
 On 18 Dec 2002, Felipe Schnack wrote:
 
  Date: 18 Dec 2002 09:12:20 -0200
  From: Felipe Schnack [EMAIL PROTECTED]
  Reply-To: Tomcat Users List [EMAIL PROTECTED]
  To: Tomcat Users List [EMAIL PROTECTED]
  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
 
 
 --
 To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
 For additional commands, e-mail: mailto:[EMAIL PROTECTED]
 
-- 

Felipe Schnack
Analista de Sistemas
[EMAIL PROTECTED]
Cel.: (51)91287530
Linux Counter #281893

Faculdade Ritter dos Reis
www.ritterdosreis.br
[EMAIL PROTECTED]
Fone/Fax.: (51)32303328


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




Re: HttpSession issues

2002-12-17 Thread Mike W-M
This is nothing in particular to do with Tomcat, more with multi-threaded
programming.
The exception is used to indicate that whatever you've started iterating
through has been changed in the meantime.
The likely scenario here is that some other request is running at the same
time as you're doing your looping and it's adding or deleting a session
attribute.  Check the java.util javadocs for more info.

I think the solution will be to synchronise the enumerating block of code,
and all other blocks that modify the session attributes, on the session
object.  It's generally good practice to minimise the amount of code that
needs to be synchronised (and the time it takes) for performance reasons.

Mike.


- Original Message -
From: Felipe Schnack [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
Sent: Tuesday, December 17, 2002 9:12 PM
Subject: HttpSession issues


  There's something problematic about the Enumeration i get from
HttpSession.getAttributeNames?
  I have some situations in my application that I have to loop thru all
my session attributes, but for some reason sometimes I get an
java.util.ConcurrentModificationException then looping them...
  The strangest thing is that a developer here get this error when he
reloads a page, but it doesn't happen when he press enter in the URL
bar... and this JSP file isn't the target of an HTML form... but
receives parameters from the query string
  I'm using JDK 1.4.1 and Tomcat 4.1.12

--

Felipe Schnack
Analista de Sistemas
[EMAIL PROTECTED]
Cel.: (51)91287530
Linux Counter #281893

Faculdade Ritter dos Reis
www.ritterdosreis.br
[EMAIL PROTECTED]
Fone/Fax.: (51)32303328


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




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