I stumbled upon an question which is not clear for me.
A. Using Java 1.4, wrap the following function in a thread so that it can be called asynchronously and provide a way for the return value to be retrieved at a later time:
B. How would the same be done in Java 5
int someMethod(int i) { return i++; }
What I think is one of the solutions: Write a class with two public methods void synchronized calculate(int i)
and int getValue()
. The calculate
starts the thread and and set a private variable.
In java 1.5 I can use AtomincInteger. Is that an answer?