• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Object locking

 
Ranch Hand
Posts: 462
Scala jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
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?

 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
both threads...


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.

Jim ... ...
 
PI day is 3.14 (march 14th) and is also einstein's birthday. And this is merely a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic