Solved

users are accessing the application at the particular time

Posted on 2014-11-12
5
211 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

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 …
ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
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.

808 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