Suppose I have a Java method:
public Ouput respond(Input input) { }
An object Outputhas many fields — some of these fields depend on the object Input, but the rest are predefined. I want to make a thread that calls respond()to return as quickly as possible.
To do this, I want to create another thread that pre-creates the object Output, sets some of the fields and puts them in the queue so that the thread executing respond()can select it from the queue, set the remaining fields and return it.
What is the best way to implement something like this? My prototype uses limited LinkedBlockingQueue, but are there any better ways to implement this idea?
My goal is to get the method as quickly as possible respond(), so other suggestions that fit this purpose are also welcome. :-)
source
share