Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how count active users

Status
Not open for further replies.

fuadhamidov

Programmer
Sep 22, 2003
98
TR
hi

i have problem with counting active users. i can count the user session object but when I re-compile any jar file in the project, sessioncreate method recount all the active sessions.
i think the problem release from that the session was not killed although i have waited form several minutes.
thanks for any help
 
If I learned form my experience, using session variables to keep track of things(# of user logins) are painful. What if a user clicks on the 'X' button instead of exiting gracefully through your app 'exit' function. That means, the # of users logged in and log out will not be correct, until the session expires(depends on the timeout value that you set for an inactive session).

>i think the problem release from that the session was not >killed although i have waited form several minutes.
>thanks for any help

If you set up the timeout value in server.xml, it will timeout properly. I never experience this problem with any versions of tomcat. I'd suggest that you double check the attribute 'maxActive' in server.xml file carefully.

~za~
You can't bring back a dead thread!
 
I don't actually think this is a major problem, as long as you control the flow of user entry and exit. Consider that you use tomcat filters to make sure that everyone coming into your site must go via a login page. This page should be a servlet which maintains a count of active users and performs two functions - login and logout. So you know know that everyone coming in goes via this servlet. Now on every other page have a .inc or code it on each page so that it utilises the javascript unonload function. This will catch users you click the X button - and you simply call the servlet that manages active users to logout. Eg :

Code:
<html>
<head>
<script language="JavaScript">
  function logout() {
    document.location = '/servlet/UserManager?action=logout';
  }
</script>
</head>
<body onUnload="logout()">
 Your web page
</body>
</html>
 
><body onUnload="logout()">

Sedj,
In my humble opinion, body unLoad will be called everytime a page unloads. It will work fine if you have this script of logout.jsp page and a user happens to click on the 'X' button instead of gracefully exiting through the application exit's function. However, you don't want this code any other pages since the function will be triggered if a user decides to abandon the page, to go to a different page, but having no intention of exiting the app. The code above I think will force the user to log out every time a page is loaded.

Also, there are other issues as well. Look at my chicken or egg thread:-


I have since abandon the session variable to keep track of users. Instead, I put logic in my codes appropriately to handle this event, regardless of whether a user clicks on the 'X' button or gracefully exit the app. In short, either in IIS or Tomcat, I set up the Session Timeout value appropriately. If the session timeout is set to 20 minutes, then I make sure that the 'killed' app will not have any detrimental effects on the app even though the page was long gone 20 minutes ago.






~za~
You can't bring back a dead thread!
 
maxpower1 :

Yes, that is something I had not considered when I posted ... thanks for the correction !

Obviously such matters require further thought - perhaps javascript *logout* function coupled with some HttpSession management in the servlet ...

Take care,

sedj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top