• 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

global session counter

 
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to write session counter that works with session's migration.
There is an example in HFS&J, but it will not work with session's migration.



How can it be improved?

EDIT
What do you think about that:
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lukas,

Is the issue that there will be an instance of the Counter class in each JVM, and so the actual count of sessions will be the sum of Counter.activeSessions variables in each JVM? If so, and short of keeping track of the session count externally (e.g. in a database), I wonder if this is even possible.

Is the A class meant to suggest a possible solution?

Thanks,
Mike
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lukas.


I think, static variables are not serializable. If we use serializable attribute, during session migration there is no guarantee that container calls writeObject() and readObject(). We don't need to use serializable attribute, container will take of that.

I would like to write session counter that works with session's migration.



Increment counter in sessionDidActivate() method of HttpSessionActivationListener' class.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Mitchell wrote:Hi Lukas,
Is the A class meant to suggest a possible solution?


Yes, but Chinmaya said that there was no guarantee that container will invoke that methods.
Using listener will be better .
What do you think?

Static variables are not the part of serialization - they are class variables, not instance variables. But I explicitly write that value to the stream and then I read it back
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mike Mitchell wrote:
If so, and short of keeping track of the session count externally (e.g. in a database), I wonder if this is even possible.


It would be possible, but there would be performance hit.
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody help?
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to keep track of the number of sessions in one JVM, then you can use SessionListener and SessionActivationListener together. Increase a counter when session is created or activated and decrease the counter if session is destroyed or passivated. If you want to know how many total sessions are there in all the JVMs, then you'll have to use some external help (like Database as Mike said)...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic