Threads : Calling same calculator with different values for different readers
posted 2 years ago
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
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.