Solved

users are accessing the application at the particular time

Posted on 2014-11-12
5
221 Views
Last Modified: 2014-11-15
Hi,
I have a web application in java written in jsp,spring running on tomcat 7.

I don't want to hit the database for the achieving the below.
How can i come to know how many users are accessing the application at the particular time through JSP?
0
Comment
Question by:Rocking
  • 3
  • 2
5 Comments
 
LVL 27

Assisted Solution

by:rrz
rrz earned 500 total points
ID: 40437676
You could use a Listener.
 import javax.servlet.http.HttpSessionListener;
 import javax.servlet.http.HttpSessionEvent;
 public class SessionCounter implements HttpSessionListener {
    public void sessionCreated(HttpSessionEvent event) {
        // here is where you can add user to a data structure
    }
    public void sessionDestroyed(HttpSessionEvent event) {
       // here is where you can remove a user 
    }
 }

Open in new window

0
 

Author Comment

by:Rocking
ID: 40439063
It means we can create a hashmap at global level and store all users which are accessing our application.
based on the size of the map we can find out the current users at a given time.
Am i correct?
0
 
LVL 27

Accepted Solution

by:
rrz earned 500 total points
ID: 40439167
Yes, you could create a application-scoped variable that would be accessible in your JSPs.
There is an example at  
http://www.experts-exchange.com/Programming/Languages/Java/J2EE/JSP/Q_20514811.html   
Look at my accepted solution. But, your case will simpler. You don't need the Filter.
0
 

Author Comment

by:Rocking
ID: 40443154
Is there any difference between using listener and filter?
0
 
LVL 27

Expert Comment

by:rrz
ID: 40443384
Yes. A Filter doesn't listen to session events.
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 101
Eclipse with gitlab 1 81
web application structure 18 102
VMWare environment audit 8 69
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question