Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

users are accessing the application at the particular time

Posted on 2014-11-12
5
Medium Priority
?
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 28

Assisted Solution

by:rrz
rrz earned 2000 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 28

Accepted Solution

by:
rrz earned 2000 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 28

Expert Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
Suggested Courses

660 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