• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HttpSessionListener

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My JSP includes an HttpSessionListener which counts the number of current sessions and also stores the maximum number of sessions.
So part of the page looks something like
"Currently serving 1 sessions ( Max 2 )"
This is working perfectly when I connect to my site from home. However, I've just connected from work (?!) for the first time and I get
"Currently serving 1 sessions ( Max 1 )"
as soon as I access the page but this drops to
"Currently serving 0 sessions ( Max 0 )"
when I click a link.
Also, I never get to the stage where I have more than one session counted no matter how many browsers I open. It's always
"Currently serving 1 sessions ( Max 1 )"
Clearly the sessions are not being monitored. I have enabled all cookies but still the problem remains.
Does anyone know the cause of this?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Without seeing your code, we would have no way of helping you with this.
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nigel King, please post your code.
 
Nigel King
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, the code for the listener is

public class SessionCounter implements HttpSessionListener
{
private int numberOfSessions = 0;
private int maxSessions = 0;

public void sessionCreated (HttpSessionEvent evt)
{
numberOfSessions++;

if ( numberOfSessions > maxSessions ) {
maxSessions = numberOfSessions;
}

}

public void sessionDestroyed (HttpSessionEvent evt)
{
numberOfSessions--;
}

public int getNumberOfSessions()
{
return numberOfSessions;
}

public int getMaxSessions()
{
return maxSessions;
}

}

As I said, it workds perfectly when I access the site from my laptop at home but not from my work PC.
Would this imply that some browser setting is preventing the creation of the session? Like I said, I've allowed all cookies.

Thanks for looking at this.
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just something I experienced and not sure it is true or false.
Under Windows XP, if I use IE, each time a new instance of IE opened and connect to the server, my server would report a new session created. If I use FireFox, new instance of it would take over an existing session, if one has opened, so to server, no new session created.
 
Ben Zung
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may be handy.
http://www.javaworld.com/javaworld/jw-07-2004/jw-0712-threadsafe.html
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you need to show us the test cases or test procedures step-by-step. I means how you create those multi-sessions.
 
Nigel King
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for all these replies.
The sessions are started when a new browser is opened.
Last night, when I went home and logged into my site from there, I found that the SessionListener wasn't working either. However, I'm absolutely sure it was when it was uploaded. And it definitely is from my local box with Tomcat running locally.
So I'm starting to think that the problem doesn't lie in the code, more in some kind of Tomcat setup.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic