Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4272868
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:38:09+00:00 2026-05-21T07:38:09+00:00

I am storing data in application scope. I want to clear this data after

  • 0

I am storing data in application scope. I want to clear this data after every hour. Infact using it as cache for one hour. What is the best way to implement this? Earlier we used session scope to store this data and it used to get expired after session gets expired. As this data is unique across the application we want to store it in application scope.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:38:10+00:00Added an answer on May 21, 2026 at 7:38 am

    We found a way to clear application scope variables using ServletContextListener and Timer.

    public class SampleListener implements ServletContextListener {
    
    public static final long _startTimerDelayMin = 10; // In minutes
    public static final long _startTimerPeriodMin = 60; // In minutes
    
    Timer timer;
    ServletContext context =null;       
    
    public void contextInitialized(ServletContextEvent contextEvent) {      
        context = contextEvent.getServletContext();     
        scheduleTimer();        
    }   
    
    public void scheduleTimer() {
        long delay = _startTimerDelayMin * 60000;   //initial delay set to _startTimerDelayMin minutes as per msecs
        long period = _startTimerPeriodMin * 60000;   //subsequent rate set to _startTimerPeriodMin minutes as per msecs
        timer = new Timer();
        timer.scheduleAtFixedRate(new RemindTask(), delay, period); 
    }
    
    public void contextDestroyed(ServletContextEvent arg0) {
        //Stopping Timer Thread once context destroyed
        timer.cancel();
    }
    
    private static String getPropertyValue(String key){
        String value = "";
        try{
            value = Util.getPropertyValueOfKey(key).trim();
        }catch(IOException e){
    
        }
        return value;
    }
    
    /**
     * This class is invoked at given interval to clear the application scope variable for browse call which have not been used for given time
     *
     */
    class RemindTask extends TimerTask {
    
        public void run() {
            clearScopeVariables();
        } 
    
        /**
         * This function has logic to clear the application scope variable for browse call which have not been used for given time
         */
        public void clearScopeVariables() {
            Date dt = new Date();
            Enumeration<String> applicationScopeVarNames = (Enumeration<String>)context.getAttributeNames();
                        // TODO: clear the scope variables
        }       
    }   
    

    Add Listener in web.xml

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the plist for storing data in iphone application, but now there is
In android application for data storing and sharing in app which one is good
My application is storing location data from GPS inputs. When importing a GPX file,
My application is storing some data in SQL Table called Transactions. Users are able
Imagine a web-application storing some data-resource with some id which stores three attachment (e.g.
I am using Microsoft Access database for storing data. In that, I stored date
I am writing a program using Delphi 2006 and storing data in XML files
I have been using the System.Data.SQLite provider for my application. When I try to
I have an application that shows some data in p:DataTable.... This table is accessible
What's the standard path on MacOS X for storing application data that is to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.