I'm relativelt inexperienced in threading so was wondering if someone could help me out. I have just had an interview where they asked my to describe a class that prices a trade. The pricing method should return a new price only if it hasn't been priced before otherwise it returns a previosly calculated price and many threads can be executing at the same time. One of the scenarios mentioned was 2 threads attempting to price the same instrument (not necessarily the same object) at the same time so it should calculate once and then return the result to both threads.
I have come up with this so far but am missing the code to determine if it is currently pricing the same object passed, any ideas?
will myers wrote:...price the same instrument (not necessarily the same object) at the
same time so it should calculate once and then return the result to
To manipulate the "same instrument" appropriately in multiple threads,
calculating only once, for example, following threads must identify the
"sameness" of the instrument. You can uniquely tag objects that are
"meaningfully equal" with a version of the equals() method.