object creation timestamp

J

Jeff

Is there an object creation timestamp that is accessible?

I have a continuous data input stream that I parse and put into a HashMap.
The key entry is a Long. The value entry is a Vector. After 5 seconds,
the data is out of date so I want to remove it from the HashMap. I would
like to test whether the Long object was created 5 or more seconds ago.

Any suggestions?

Thanks
 
E

Eric Sosman

Jeff said:
Is there an object creation timestamp that is accessible?

Not unless you arrange for one.
I have a continuous data input stream that I parse and put into a HashMap.
The key entry is a Long. The value entry is a Vector. After 5 seconds,
the data is out of date so I want to remove it from the HashMap. I would
like to test whether the Long object was created 5 or more seconds ago.

Any suggestions?

Don't use a Long. Invent a class that contains your
Long and a timestamp, e.g.:

class LongWayToTipperary {
long creationTime = System.currentTimeMillis();
Long payloadObject;
...
}

If your aging criterion has a little "play" in it (e.g.,
if it's permissible to annihilate an object after only 4.99
seconds, or to allow another to live to 5.02 seconds), there
may be better approaches than tagging every single object at
creation time. For example, you might build a HashMap-like
object containing five or six actual HashMaps, each covering
one second's worth of data. At each one-second tick, you'd
cycle the HashMaps, discarding the oldest and starting fresh
with an empty youngest to hold all data until the next tick.
Depends on what you're trying to do, really.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top