Solved

users are accessing the application at the particular time

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 57
scoresSpecial  challenge 13 46
userCompare  challenge 3 68
ArrayIndexOutOfBoundException 9 68
Convert websphere application server default chained Certificates from 1024 to 2048 keysize or higher size and also you can change signatureAlgorithm . Please make sure Websphere Application Server fixpack 7.0.0.23 or Above. The following steps a…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now