On Aug 15, 2008, at 9:27 AM, Jarek Gawor wrote:
On Mon, Aug 11, 2008 at 12:43 PM, Dain Sundstrom <[EMAIL PROTECTED]>
wrote:
I'm not sure. One thing I don't think should be changed in the
spec is the
async message signature, which is something like this:
Future<ReturnType> asyncMethod(Params);
Ahh, yes. I didn't know it was defined like that by the spec. I just
looked at the draft spec a bit and it seems like the
performCalculation() method example that supposed to demonstrate
asynch invocation is implemented synchronously. I wondering if we
could get it updated to use ExecutorService or mention JSR 236, e.g.
do something like that:
@Resource
ManagedExecutorService executorService;
@Asynchronous
public Future<Integer> performCalculation(...) {
Callable<Integer> task = new Callable<Integer> () {
public Integer call() throws Exception {
// ... do calculation
Integer result = ...
return result;
}
}
return executorService.submit(task);
}
The problem with that style execution is the executor service would
have to assign a thread to the callable so you end up with a blocking
thread anyway. BTW, I expect this pattern to be very popular if the
EJB spec committee doesn't provide some sort of notification system.
Maybe I'll get to coin the first pattern for JEE6 :)
I don't know if it is possible, but maybe the EJB spec could also be
extended to support AynchListener to be passed as a parameter when
invoking asynch functions, for example:
@Asynchronous
public Future<Integer> performCalculation(..., AsynchListener
listener) {
Callable<Integer> task = new Callable<Integer> () {
public Integer call() throws Exception {
// ... do calculation
Integer result = ...
return result;
}
}
return executorService.submit(task, new
ManagedTaskListenerWrapper(listener));
}
I think that could get you what you want. The JAX-WS Dispatch API
(http://java.sun.com/javase/6/docs/api/javax/xml/ws/Dispatch.html)
already has similar API (but that's purely for clients).
Wow, didn't know that WS had addressed this already. That could be
good ammo for convincing the EJB spec committee.
But I understand the problem now and I will try to bring it up to
the EG.
I think having a Completion service like I described in the earlier
email would be a big step forward for all of the specs. It could be
used for EJB and JAX-WS (with an adapter), and could be really useful
for any async framework.
-dain