so right now i have a hashmap which stores Calendar objects (just need a way to store dates). each value stores two Calendar objects, one representing the start of an event, and the other the end of it. The user enters these through a gui, and they can span weeks and months.
What i need to do is be able to remove these entries when they expire, meaning their second Calendar object has passed according to the real world date. I want this to be done automatically as long the instance is running.
My idea was to have a timer thread running and once a week it could go through all the entries in the hashmap and remove the ones that have expired. I know its not all that practical, its for a school project. But I was just looking for ideas or design pattern that could help implement this in an efficient manner.
Thanks and let me know if you need any more information.
Having a background thread that performs maintenance tasks is a good idea and is very common practice. Be warned though that a Hashmap is not thread safe so you will need to synchronize its access, or replace with a thread safe class such as ConcurrentHashMap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With