Solved

users are accessing the application at the particular time

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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.

707 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