DD.
DD.

Reputation: 21971

Java timestamps: Joda vs Date vs Long

I need to record timestamps for my trading system (order sent time,ack time, complete time) with millisecond accuracy.

Trying to think what the best way of representing this information is...I need to record for analysing performance/latency between the different timestamps...

Is there any point in using a Joda instant? Not sure what advantages this has over a Java Date for just storing a UTC datetime.

Not sure if I even need to use Date as I can't think why I would need this right now...However, its a bit more explicit instead of using a long...

Any thoughts on how best to approach this? I imagine it will take a long time to refactor this later if I make the wrong decision.

Upvotes: 3

Views: 1728

Answers (1)

Shaggy Frog
Shaggy Frog

Reputation: 27601

Usually time handling tasks end up way harder than they look on the surface. If you're doing any sort of non-trivial manipulations with time values -- besides just taking their difference as you suggest in your question -- you should seriously consider Joda. Joda is a very comprehensive library.

So perhaps start off with long values first, and refactor to Joda if you realize you're needing to reinvent the wheel later.

(You also want to consider the other side effects of adding a library to your system -- whether that's increased memory usage or decreased cycles. You mention you're building a trading system, which I think tend to be high-performance systems with very particular requirements.)

Upvotes: 5

Related Questions