It's not a secret anymore!*
The moose likes Performance and the fly likes SessionListener online users - Splitting up lists Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "SessionListener online users - Splitting up lists" Watch "SessionListener online users - Splitting up lists" New topic
Author

SessionListener online users - Splitting up lists

Tristan Van Poucke
Ranch Hand

Joined: Jun 30, 2008
Posts: 47
Hi

I'm using a SessionListener to check if a user is online or not.
It basically keeps a List of all online users.
Too check if one is online or not I use "contains()".

If there were say a few 1000 users online it would take a while to perform "contains()".
That's why I thought of splitting up the lists in a few lists identified by the first 3 chars or so of the users id.


Is this the way to go, or are there other, better ways of doing this?

Tnx
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12681
    
    5
The obvious choice for a collection is to use a implementation of the Set interface, for example HashSet - essentially a Map where the entry (user name) is both value and key.

This sort of lookup uses a Hashcode and is very very fast compared to brute force lookups with (for example) an ArrayList.

Bill


Java Resources at www.wbrogden.com
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: SessionListener online users - Splitting up lists
 
Similar Threads
using classes from other modules in web.xml
number of users online
Maintaining lists of beans in a page
Use five 5s to make 37
how to display Form and Canvas based UI together?