• 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

Session count tracking is lost when Tomcat restarted

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
We are doing a web application. We are providing Licence for that application( including No. of concurrent users). To track the user sessions, I created a class SessionCounter with a static field for Active sessions. When a session is created, I'm checking the Active session counter against the Maximum users (taken from License file). If the Maximum count is reached, I'm redirecting to a 'Invalid Session' page. We are using only servlets.
Now what the problem is, whenever the Tomcat is restarted, the Active session count which is a static field, is initialized to 0. For example, the Maximum allowed user is 3. Now 3 users are accessing. If the Tomcat is restarted, further 3 users can access the application. Again if restarted 9 users can access the application.

Anybody has any other solution for this problem?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Naturally if you are storing the counetr in memory, it will get reset when the classes are reloaded.

If you need the count to persist across reloads, you'll need to persist it to a database or the file system.
 
sundaramoorthi thangavel
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear Bibeault,
Thanks for your reply. I considered that option also. But it is also having some problem. Consider the scenario below.

* We gave license for 2 users
* When the first session is created, we are incrementing the count by 1 in database
* When the second user accesses, we are again incrementing the count by 1.
* If the 3rd user tries to access, we are redirecting to the error page. No Problem.( because it reached the Maximum users allowed)

* Suppose network is down for a minute. At that time those two users close the application. When the net is up, again they are tring to access the application. In this scenario, no users will be allowed to access the application. Because the count in database is 2(Maximum users). We have to manually reset the counter in database otherwise it won't work.
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Invalidate all sessions on server restart.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the two users log-out, you have to reset the counters in the database to zero. These counters have to be updated everytime a user logs in and logs out.
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the server ( tomcat ) is restarted how can the previous three access the system ??? They wont be holding valid sessions right , since the server would have destroyed all session objects while restarting....

So the method you choose is correct , but instead of storing the field in some static attribute store it in ApplicationContext . When any one logs in , increase the cound in application context and put some identifier in clients current session object . Now if network is down , first see that if the session client wants is still alive if yes no problem , if no session is alive , check in application context if the count is lesss than N , if yes create a new session and continue. !! Write a session listener that will reduce the cound in application context variable
 
sundaramoorthi thangavel
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you all for giving me a good direction. Now I realize, we haven't implemented proper session tracking. I'm going to rewrite. Thank you all.
 
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

Originally posted by sundaramoorthi thangavel:
....
* Suppose network is down for a minute. At that time those two users close the application. When the net is up, again they are tring to access the application. In this scenario, no users will be allowed to access the application. Because the count in database is 2(Maximum users). We have to manually reset the counter in database otherwise it won't work.



If the app is down, they're not going to be able to invalidate their sessions.
They can close the browser but that won't invalidate the sessions.
This will be the case whether even if the app is not down.

Servlet apps have no, reliable, way of knowing that a user has closed their browser (or lost network connectivity, etc...)

No matter where you store the current session count, your going to have the problem of people taking seats that they are no longer using; until the unused session times out on the server.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic