Asynchronous method calls - II

4 May 2008

Do read the first part of this post. In this post, I will prenset another example of asynchronous method calls in EJBeans.

Lets take another example for better understanding. In the given example, we call on the normal remote interface while “waiting” for the asynchronous call.

   System.out.println("-------- Synchronous call");
   ret = echo.echo("normal call 2");
   System.out.println(ret);

After doing everything we wish to do while waiting for the asynchronus call to complete, we have to cast the asynchronus proxy to AsynchProvider and then have to get hold of the Future contained.

      System.out.println("-------- Result of Asynchronous call");
      AsynchProvider provider = (AsynchProvider)asynchEcho;
      Future future = provider.getFuture();

Now is the time to make sure that the asynchronus invocation has completed and then we should get the return value of the asynchronus invocation.

      System.out.println("Waiting for asynbch invocation to complete");
      while (!future.isDone())
      {
         Thread.sleep(100);
      }
      ret = (String)future.get();
      System.out.println(ret);

Happy coding!!!

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

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 - II

Leave a Reply