File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Object locking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Object locking" Watch "Object locking" New topic
Author

Object locking

Will Myers
Ranch Hand

Joined: Aug 05, 2009
Posts: 331

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?

Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
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 ... ...


BEE MBA PMP SCJP-6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object locking