I need to convert a sync method like next:
method (String, String, Object)
to an async method.
The main problem is that we work with Java 1.4 and I can't use Executor, Future, ...
Any ideas?
I need to convert a sync method like next:
method (String, String, Object)
to an async method.
The main problem is that we work with Java 1.4 and I can't use Executor, Future, ...
Any ideas?
Define a callback interface (if one isn't already available) and make your method take the interface as a parameter. The method will go off and do its work, and when it's finished, it calls the callback.
Example:
becomes
where
Callback
is something likeIt's preferable to use generic types for the
Callback
result (GWT, for example, uses a genericAsyncCallback<ResultType>
that is identical to the interface above), but since generics aren't available in 1.4, you can either useObject
and cast or have differentCallback
interfaces for different returns. Compare with any of the*Listener
interfaces in Swing/AWT.