You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jacob Champlin <jc...@emocorp.com> on 2005/05/03 23:29:53 UTC
Concurrency Issue With a SessionListener.
I am having issues with a SessionListener I have written. The purpose of
the Listener is to maintain a List of Active Users on the site. Here is
the code for the Listener.
// BEGIN CODE
public class ActiveUsersListener implements Serializable,
HttpSessionListener {
public static Set activeSessions = new HashSet();
public void sessionCreated(HttpSessionEvent event) {
activeSessions.add(event.getSession());
}
public void sessionDestroyed(HttpSessionEvent event) {
activeSessions.remove(event.getSession());
}
public static List getActiveUsers() {
List users = new ArrayList();
Iterator sessionIter = activeSessions.iterator();
HttpSession session = null;
EmoUser user = null;
while (sessionIter.hasNext()) {
session = (HttpSession) sessionIter.next();
user = (EmoUser) session.getAttribute(EmoUser.SESSION_KEY);
if (user != null & user.hasLoggedIn()) {
users.add(user);
}
}
return users;
}
}
// END CODE
I then have a webpage that calls ActiveUsersListener.getActiveUsers() to
list out all the active users on the site. Note: I don't just store the
User objects because the user object doesn't get created until the user
logs in.
So the problem I am having is that this code works fine on a single box
under Tomcat 5.5.4 . However, as soon as we go into a cluster we get
lockups in Tomcat. The server is completely unresponsive, and there are
no log/error messages.
Because of this I am assuming we have a concurrency issue, however I
have no idea where the problem is.
A few more bits of information, we persist sessions to file system on
shut down, and we use in memory session replication only when
session.setAttribute() is called (DirtyFlag).
Thank you in advance for any help.
Jacob Champlin
EMO Corporation
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
Re: Concurrency Issue With a SessionListener.
Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
I had to do almost the exact same thing a while back...
I'm not sure what the source of your lockup is, although I can say my
code synchronized on what would be your activeSessions Set any place it
was accessed (probably more than I had to frankly)... I'm not even sure
there would have been concurrency issues anyway frankly, but it seemed
like a good idea at the time :)
One issue I'm not sure you have thought of though, and I suppose it
could have to do with the lockup, although I'm not sure how... your list
of users will be unique to each node in the cluster.
You would have an instance of ActiveUsersListener on each node, and each
of those would have its own activeSessions Set, so you wouldn't have a
consolidated list of users on your site, you'd have a list of users on a
given node in each instance of the listener... further, if a user hits
one node during logon, and then is directed to another, and during that
request you try and retrieve the session from activeSessions, it won't
be there because its in the version of activeSessions on the first node.
Where specifically does the lockup occur, meaning, is it during logon or
a listing of users? I'd bet you can see enough in the log to at least
tell what method your in (well, not as the code is posted... throw some
log outputs in sessionCreated(), sessionDestroyed() and getActiveUsers()
so you can at least see the last place you wind up... hell, I'd put log
messages around every single line in this listener so I could tell
exactly where it was failing.
Frank
Jacob Champlin wrote:
> I am having issues with a SessionListener I have written. The purpose of
> the Listener is to maintain a List of Active Users on the site. Here is
> the code for the Listener.
>
>
> // BEGIN CODE
>
> public class ActiveUsersListener implements Serializable,
> HttpSessionListener {
>
> public static Set activeSessions = new HashSet();
>
> public void sessionCreated(HttpSessionEvent event) {
> activeSessions.add(event.getSession());
> }
>
> public void sessionDestroyed(HttpSessionEvent event) {
> activeSessions.remove(event.getSession());
> }
>
> public static List getActiveUsers() {
> List users = new ArrayList();
> Iterator sessionIter = activeSessions.iterator();
> HttpSession session = null;
> EmoUser user = null;
> while (sessionIter.hasNext()) {
> session = (HttpSession) sessionIter.next();
> user = (EmoUser) session.getAttribute(EmoUser.SESSION_KEY);
> if (user != null & user.hasLoggedIn()) {
> users.add(user);
> }
> }
> return users;
> }
>
> }
>
> // END CODE
>
> I then have a webpage that calls ActiveUsersListener.getActiveUsers() to
> list out all the active users on the site. Note: I don't just store the
> User objects because the user object doesn't get created until the user
> logs in.
>
> So the problem I am having is that this code works fine on a single box
> under Tomcat 5.5.4 . However, as soon as we go into a cluster we get
> lockups in Tomcat. The server is completely unresponsive, and there are
> no log/error messages.
>
> Because of this I am assuming we have a concurrency issue, however I
> have no idea where the problem is.
>
> A few more bits of information, we persist sessions to file system on
> shut down, and we use in memory session replication only when
> session.setAttribute() is called (DirtyFlag).
>
> Thank you in advance for any help.
>
> Jacob Champlin
> EMO Corporation
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>
>
>
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org