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.
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.
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
Joined: Jul 18, 2006
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.
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.