in Education by
I'm using JEE and I created EJB-Singleton. It has as a field LRUMap, which represents cache to store data in application. I want to clear that data inside singleton or just kill and start again whole singleton during runtime. Is there any option to do that periodically? For example to reset singleton bean once per day in order to clear data? Here is the code: @Singleton @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER) public class BpNotificationCacheBean { private static final int CACHE_SIZE = 1000; private Map cacheMap; @PostConstruct public void init() { cacheMap = new LRUMap(CACHE_SIZE); } @Lock(LockType.WRITE) public Boolean get(String businessPartnerId) { return cacheMap.get(businessPartnerId); } @Lock(LockType.WRITE) public void put(String businessPartnerId, Boolean isVIP) { this.cacheMap.put(businessPartnerId, isVIP); } } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
If you're in a full JEE environment, I'd create a Schedule annotated method: import javax.ejb.Schedule; @Singleton @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER) public class BpNotificationCacheBean { private static final int CACHE_SIZE = 1000; private Map cacheMap; ... @Lock(LockType.WRITE) @Schedule(hour = "1", persistent = false) private void resetCache() { cacheMap = new LRUMap(CACHE_SIZE); } } The key is the Schedule annotation which is part of the Java EE Timer Service. The annotation I show runs a 01:00 (1AM) every day but see the docs to show how to change that.

Related questions

0 votes
    Which annoatation is used to inject singleton services like timer service into an ejb?...
asked Nov 7, 2020 in Technology by JackTerrance
0 votes
    What is singleton class in android?...
asked Jan 14, 2021 in Technology by JackTerrance
0 votes
    How to prevent cloning of a singleton object?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    Can we create a clone of a singleton object?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    What are the difference between a static class and a singleton class?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    How can you create Singleton class in java?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    What is Singleton pattern?...
asked Nov 7, 2020 in Education by Editorial Staff
0 votes
    What does the command git reset –hard HEAD ~3 do? A. Merges the last 3 commits to the master B. Discards ... nothing D. Resets the head to 3 commits before the current commit...
asked Dec 23, 2022 in Technology by JackTerrance
0 votes
    What is the command to reset your index as well as the working directory to the state of your last commit? A. git clean B. git reset C. git revert D. git checkout...
asked Dec 21, 2022 in Technology by JackTerrance
0 votes
    What does the command Git reset –- soft HEAD^ perform? A. Moves commit to one after current head B. Moves commit ... . Moves commit to the first head D. None of the options...
asked Dec 21, 2022 in Education by JackTerrance
0 votes
    I have two buttons in MainActivity, the first one opens a custom DialogFragment with some spinners and in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 11, 2022 in Education by JackTerrance
0 votes
    I'm using const embed = new Discord.RichEmbed(); for my embeds. How do I reset the Embed values? ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 29, 2022 in Education by JackTerrance
0 votes
    In my password reset function the user can put in whatever he/she wants. It does not even needs ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I'm making a drag and drop game for my A level computing coursework. My drag and drop works fine, but I have 6 ... >= 190 && theButton.Location.X = 42 && theButton.Location.Y...
asked Apr 9, 2022 in Education by JackTerrance
0 votes
    I want to create a request from my application. (iOS and Android - Coded with Xamarin). Explaination: ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
...