aspose file tools*
The moose likes Threads and Synchronization and the fly likes Threads : Calling same calculator with different values for different readers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Threads : Calling same calculator with different values for different readers" Watch "Threads : Calling same calculator with different values for different readers" New topic
Author

Threads : Calling same calculator with different values for different readers

Devendra Walanj
Greenhorn

Joined: Apr 21, 2010
Posts: 12
Hello All,

There is one class that performs a calculation and many readers that are waiting to receive the completed calculation. At any given moment many readers may be waiting.
But I want to call the readers with different figures

all I get is the same value in return



Keep Moving Forward
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

The first thing you have to do is come up with a detailed specification. What do you want to do - in detail. What does 'different figures' mean, who generates them. Once you know how to do that, how does each client respond to the 'figure' or value or whatever. What do you want other readers to do?

Treat the specification for how the calculator works completely different from how the reader works (i.e. don't say readers should get different values from the calculator, maybe say 'calculator should produce x number of values, and for each value notify consumers that it is ready).

Think of what should happen when things overlap. If calculator produces a value, then notifies someone, can calculator go on to make a new value? How does that affect the reader which was notified?

Once you have a good specification, then you can start translating it into discreet steps, and once you have steps you can turn it to code. But to try to code when it isn't clear what the expectation is is not very productive.


Steve
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Threads : Calling same calculator with different values for different readers