1

I have a main class in which I am calling java method with @Asynchronous annotation on it. I have imported javaeeAPI6.jar for it but the method runs synchronously. Please tell me what is not right. I have added a long for loop to check whether the code goes into next statement past the asynch asyncrounousCall() call but it hangs on it

import javax.ejb.Asynchronous;
public class TestClass
{

public static void main (String[] args)
{

    System.out.println("synch");

    createAsyncrounousDocument("", "");

    System.out.println("synch");        
}

@Asynchronous
public static void asyncrounousCall() 
{
    for(int i = 0; i < 9999999999L ; i++)
        i = i;

    System.out.println("asynch");
}

}

Thank you Aiden

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Aiden
  • 460
  • 2
  • 11
  • 29
  • 4
    That's because you call it synchronously. The fact it has an `@Asynchronous` annotation is irrelevant because it's just being invoked like a plain ole' Java method. – Andy Turner Jan 19 '16 at 11:33
  • Thanks so very much for telling. How do I call it asynchronously ? Do I add some other annotation ? – Aiden Jan 19 '16 at 11:38
  • 2
    it's not a question of adding annotations. You actually have to have this method be invoked by a framework capable which knows what that annotation means. Try searching for a tutorial on `@Asynchronous` (e.g. [this one](http://docs.oracle.com/javaee/6/tutorial/doc/gkkqg.html)). – Andy Turner Jan 19 '16 at 11:40
  • Dropping arbitrary Java EE related JARs in a Java SE application project absolutely doesn't make it a Java EE application. Stop and restart at https://docs.oracle.com/javase/tutorial/essential/concurrency to learn how to do concurrenty in Java SE. – BalusC Jan 19 '16 at 12:33
  • Possible duplicate of [@Async not working for me](http://stackoverflow.com/questions/4060718/async-not-working-for-me) – kryger Jan 19 '16 at 12:56

0 Answers0