i've a method takes an argument and returns a value, the above
method will do some operations which is time consuming, so the caller
is blocked till the processing is finished.
Now i want to make it as asynchronous. one way of doing this is
callback mechanism.
is there any other design for this. mine is a java program.
Thanks in advance
Philipp Leitner - 17 Nov 2007 16:15 GMT
There are a few standard approaches to asynchrony. Callback is one of
them, Poll Objects (or Futures) are another one. In this design the
async method immediately returns a 'proxy' that will receive the
result as soon as it is available, i.e., the proxy can be 'polled' for
the result.
Ultimately, Poll Objects are only a wrappers for callbacks, but
sometimes this design is simmpler to handle and easier to understand
for the client.
/philipp
Daniel Pitts - 17 Nov 2007 17:57 GMT
> i've a method takes an argument and returns a value, the above
> method will do some operations which is time consuming, so the caller
[quoted text clipped - 3 lines]
> is there any other design for this. mine is a java program.
> Thanks in advance
There are a few ways to handle this.
Callback is probably the best approach, however you can also use
Executor and other java.util.concurrent classes.
I suggest reading the book Java Concurrency In Practice. Its been very
useful to me in my exploration of Java concurrency.
<http://virtualinfinity.net/wordpress/technical-book-recommendations/java-concurr
ency-in-practice/>
Good luck,
Daniel.

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>