That is interesting. Thank you for the suggestion.
-----Original Message-----
From: Laird Nelson <ljnelson_at_gmail.com<mailto:Laird%20Nelson%20%3cljnelson_at_gmail.com%3e>>
Reply-to: Laird Nelson <ljnelson_at_gmail.com>
To: users_at_glassfish.java.net<mailto:users_at_glassfish.java.net>
Subject: Re: Asynchronus
Date: Tue, 12 Jul 2011 13:27:07 -0700
On Tue, Jul 12, 2011 at 1:09 PM, Collins, Russell <rcollins_at_corelogic.com<mailto:rcollins_at_corelogic.com>> wrote:
This works if I pull out the asynchronous methods and place them in a separate ejb and call it from the order class. This works for me. Thanks for your help.
You can also do this:
@Stateless(name = "Order")
public class Order implements IOrderLocal {
@Resource
private SessionContext sessionContext;
public void processOrder() {
assert this.sessionContext != null;
final IOrderLocal me = this.sessionContext.getBusinessObject(IOrderLocal.class);
assert me != null;
final Future<String> o1 = me.m1();
final Future<String> o2 = me.m2();
System.out.println(o1);
System.out.println(o2);
}
}
Best,
Laird
-----Original Message-----
From: Marina Vatkina <marina.vatkina_at_oracle.com<mailto:Marina%20Vatkina%20%3cmarina.vatkina_at_oracle.com%3e>>
Reply-to: Marina Vatkina <marina.vatkina_at_oracle.com<mailto:marina.vatkina_at_oracle.com>>
To: users_at_glassfish.java.net<mailto:users_at_glassfish.java.net>
Subject: Re: Asynchronus
Date: Tue, 12 Jul 2011 12:15:26 -0700
Russell,
Calling any method from inside an EJB via 'this' is an internal call
that bypasses any container involvement.
-marina
Collins, Russell wrote:
> I am wondering how this @Asynchronous annotation is tor work in
> Glassfish 3.0.1. Currently, this does not produce any type of
> Asynchronous processing as far as I can tell. Here is my class
>
>
> @Stateless(name = "Order")
> public class Order implements IOrderLocal {
>
>
> @Override
> public void processOrder() {
>
>
> Future<String> o1 = this.m1();
> Future<String> o2 = this.m2();
>
> System.out.println(o1);
> System.out.println(o2);
>
> }
>
>
>
> @Asynchronous
> public Future<String> m1() {
>
> boolean truth = true;
> int n = 0;
>
> System.out.println("Inside m1");
>
> while(truth) {
>
> n += 1;
> if (100 == n)
> truth = false;
>
> System.out.println("Inside m1 loop");
> }
>
> System.out.println("About to return m1");
> return new javax.ejb.AsyncResult<String>("Hello, Async 1 World!");
> }
>
> @Asynchronous
> public Future<String> m2() {
>
> System.out.println("About to return m2");
> return new javax.ejb.AsyncResult<String>("Hello, Async 2 World!");
> }
> }
>
>
>
> The first time I ran this, I ran a loop 10 times. The result is as
> follows:
>
> INFO: Inside m1
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: About to return m1
> INFO: About to return m2
> INFO: javax.ejb.AsyncResult_at_1cf166b2
> <mailto:javax.ejb.AsyncResult_at_1cf166b2>
> INFO: javax.ejb.AsyncResult_at_1cf16add
> <mailto:javax.ejb.AsyncResult_at_1cf16add>
>
> When I run it 100 times. The result is as follows:
>
>
> INFO: Inside m1
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: Inside m1 loop
> INFO: About to return m1
> INFO: About to return m2
> INFO: javax.ejb.AsyncResult_at_1cd1d81c
> <mailto:javax.ejb.AsyncResult_at_1cd1d81c>
> INFO: javax.ejb.AsyncResult_at_1cd1f33d
> <mailto:javax.ejb.AsyncResult_at_1cd1f33d>
>
> In both instances, the second "asynchrous" call is not being executed
> until the first one is complete. I would like both methods to execute
> at the same time. Is this a JEE thing or is this a bug in Glassfih 3.0.1?
>
>
> *Russell Collins*
> Sr. Software Engineer
> CoreLogic Spatial Solutions
> Direct: 512.977.3206<tel:512.977.3206>
> rcollins_at_corelogic.com<mailto:rcollins_at_corelogic.com> <mailto:rcollins_at_corelogic.com>
>
>
>
> "Do or do not, there is no try." - Yoda
>
>
>
> ******************************************************************************************
>
> This message may contain confidential or proprietary information
> intended only for the use of the
> addressee(s) named above or may contain information that is legally
> privileged. If you are
> not the intended addressee, or the person responsible for delivering
> it to the intended addressee,
> you are hereby notified that reading, disseminating, distributing or
> copying this message is strictly
> prohibited. If you have received this message by mistake, please
> immediately notify us by
> replying to the message and delete the original message and any copies
> immediately thereafter.
>
> Thank you.
> ******************************************************************************************
>
> CLLD
> ------------------------------------------------------------------------
>