[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openejb-development
Subject:    Re: Async bean idea
From:       "Jarek Gawor" <jgawor () gmail ! com>
Date:       2008-08-15 18:46:30
Message-ID: 5eb405c70808151146w52cd4547y4175a8463f5baac6 () mail ! gmail ! com
[Download RAW message or body]

On Fri, Aug 15, 2008 at 1:44 PM, Dain Sundstrom <dain@iq80.com> wrote:
>> 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.

Well, yeah. Certain tasks are not asynch in nature so you have to run
them in a separate thread. But some are, and there is no point of
submitting them through the ExecutorService. For example, in case of
the Dispatch API, you could implement the performCalculation()
function as:

@Asynchronous
public Future<Integer> performCalculation(...) {
    return (Future<Integer>)dispatch.invokeAsynch(....);
}

I think in most cases you will deal with synch tasks that you will
need to execute in a separate thread.

The point I was trying to make here was that the example in the spec
which shows something opposite to the idea that it's trying to
describe. I also found one example on the web that has exactly the
same problem.

Jarek
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic