Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads : Calling same calculator with different values for different readers

 
Devendra Walanj
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic