Asynchronous method calls - I

4 May 2008

Methods called on the asynchronous proxy will be executed asynchronously, and the results can be obtained later on.

To execute methods asynchronously in EJB 3.0, one can use asynchronous proxy. This allows calling methods at an instance, and collecting the results later. Good thing is that there exist a JBoss extension to EJB 3.0, which allows obtaining asynchronous proxy from the remote or local interface of a stateful session bean, stateless session bean or service bean.

The following code snippet obtains the remote interface of the bean and then calls a method. Standard synchronous usage pattern is being used.

   InitialContext ctx = new InitialContext();
   Echo echo = (Echo)ctx.lookup(org.jboss.tutorial.asynch.bean.Echo.class.getName());
   System.out.println("-------- Synchronous call");
   String ret = echo.echo("normal call");
   System.out.println(ret);

Now lest see how to obtain the asynchronous proxy and how to make a call via that. Doing this will invoke the method asynchronously :

   Echo asynchEcho = Asynch.getAsynchronousProxy(echo);
   System.out.println("-------- Asynchronous call");
   ret = asynchEcho.echo("asynchronous call");
   System.out.println("Direct return of async invocation is: " + ret);

Its easy as shown in the example above. You can obtain the asynchronous proxy by calling org.jboss.ejb3.asynchronous.Asynch.getAsynchronousProxy() . All methods invoked on this proxy are invoked asynchronously, and the returned value will always be null.

Continued …

del.icio.us:Asynchronous method calls - I  digg:Asynchronous method calls - I  spurl:Asynchronous method calls - I  wists:Asynchronous method calls - I  simpy:Asynchronous method calls - I  newsvine:Asynchronous method calls - I  blinklist:Asynchronous method calls - I  furl:Asynchronous method calls - I  reddit:Asynchronous method calls - I  fark:Asynchronous method calls - I  blogmarks:Asynchronous method calls - I  Y!:Asynchronous method calls - I  smarking:Asynchronous method calls - I  magnolia:Asynchronous method calls - I  segnalo:Asynchronous method calls - I  gifttagging:Asynchronous method calls - I

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Asynchronous method calls - I

Leave a Reply