Suppose I have a Java method like:
public Ouput respond(Input input) { /* .. */ }
The Output
object has many fields - some of those fields depend on the Input
object but the rest are pre-determined. I want to make the thread which calls respond()
to return as fast as possible.
For this I want to spawn another thread which pre-creates Output
object, sets some of the fields and puts them in a queue so that the thread running respond()
can pick it up from the queue, set the remaining fields and return it.
What is the best way to implement something like this? My current prototype uses a bounded LinkedBlockingQueue
but are there better ways to implement this idea?
My aim is to get the respond()
method as fast as possible, so other suggestions which meet that goal are also welcome. :-)