I am using Spring 3.2.2.RELEASE version . The @Async anotation is not working as expected .
applicationContext.xml
<?xml version="1.0" encoding="windows-1252"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- Enable AspectJ style of Spring AOP -->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<context:component-scan base-package="com.pratik" />
<tx:annotation-driven />
import.java
public String async() {
final String asssetImportId = ObjectId.get().toHexString();
process.asyncTest();
logger.info("Ongoing");
return asssetImportId;
}
process.java
@Async
public void asyncTest() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
logger.info("After Sleep");
}
The After Sleep log should print last but it is getting printed before ongoing