• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

global session counter

 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • 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:
 
Mike Mitchell
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Chinmaya Chowdary
Ranch Hand
Posts: 432
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody help?
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ankit Garg
Sheriff
Posts: 9497
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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)...
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic