aspose file tools*
The moose likes Java in General and the fly likes Object destroyed automatically in 20 seconds from Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Object destroyed automatically in 20 seconds from Map" Watch "Object destroyed automatically in 20 seconds from Map" New topic
Author

Object destroyed automatically in 20 seconds from Map

Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
Dear All.

I need to make a Map in which I will store a key value pair.but condition is that every object which is being stored should be destroyed automatically in 20 seconds.

please help me.

Thanks a Lot.

Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4246
    
    7

It sounds like you need two things to make this work.

1. The time the object is stored in the map needs to be stored somewhere. Maybe the key or value could contain that time, or maybe you could have a second map that is key => Date.

2. You need a thread that regularly checks the times, and removes key/values that have expired. (And make sure you synchronize access to the map when you do that!).

Does that make sense?
Punya Pratap Singh
Ranch Hand

Joined: Nov 23, 2010
Posts: 80
Thanks Matthew for your reply.

But I am quite new to this(MultiThreading), so want some more help and clear Explanation or if possible then some code also .


Thanks a lot.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36599
    
  16
You could create a key object which includes the timeI presume you will be able to work out how that class works. Make sure your Map supports this method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object destroyed automatically in 20 seconds from Map
 
Similar Threads
How to make private member more secure ?
Map map = new Hashmap()
Help in stateless and stateful beans
ServletOutputStream performance.
Refresh jsp page