-
Sep 18th, 2012, 06:18 AM
#1
Help @Async not working!
Hi,
I am trying to make a async call to a method using @Async. But when I run my test case it does not run asynchronously. Please help.
Following is my code:
================
Class Having @Async: -
================
public class DeployerHelper {
@Async
public void asyncDeploy(final long userId, final long jobId, final String deployerXml) {
System.out.println("Started processing the Job: " + jobId);
// TODO: process xml
deploy();
System.out.println("Finished processing the Job: " + jobId);
}
private void deploy() {
System.out.println("Deploying.....");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
log.warning("Thread interrrupeted");
}
}
}
================
Test Class: -
================
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"application.xml"})
public class DeployerHelperTest extends TestCase {
private DeployerHelper deployerHelper;
@Before
public void setup() {
assertNotNull(deployerHelper);
}
@Test
public void asyncDeploy() {
System.out.println("**** Start: Deployer Async ****");
deployerHelper.asyncDeploy(1, 1, "TET");
System.out.println("**** End: Deployer Async ****");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Resource
public void setDeployerHelper(DeployerHelper helper) {
this.deployerHelper = helper;
}
}
================
application xml : -
================
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schem...ntegration.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schem...g-task-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" default-autowire="byName">
<beans:bean id="deployerHelper" class="com.newscale.comps.supportability.controlle r.DeployerHelper">
<beans
roperty name="logDirPath" value="Deployer/logs" />
</beans:bean>
<task:executor id="threadPoolTaskExecutor" pool-size="10" />
</beans:beans>
-
Sep 18th, 2012, 06:48 AM
#2
Please use [ code][/code ] tags when posting code...
Why should it run async... There is only an annotation and nothing that understands that annotation, so basically your @Async is useless. I suggest you read the reference guide...
-
Sep 18th, 2012, 12:29 PM
#3
Thanks Marten for your reply.
some doubts: -
1. I do not understand what you meant by "use [ code][/code ] tags when posting code...".
2. My @Async was useless because I had missed the "<task:annotation-driven executor="myExecutor" />" right?
i. After adding the code I am running into the following error: "java.lang.NoSuchMethodError: net.sf.cglib.proxy.Enhancer.setInterceptDuringCons truction(Z)V"
ii. I tried various combinations of cglib jar (cglib2_2_full.jar, cglib2_1_3.jar, cglib-nodep-2_1_3.jar etc.), none of them work. Any idea how could I get this fixed?
-
Sep 19th, 2012, 01:08 AM
#4
1. as stated use [ code][/code ] tags around your code/xml/stacktraces that way it remains readable
2. Correct use the 2.2.2 nodep jar also make sure that you only have it in your classpath once.
-
Sep 19th, 2012, 03:11 AM
#5
Thank you very much.
cglib2_2.jar as well as cglib2_2_2node jar work fine (using it one at a time) with the above code in a standalone project having spring and other necessary jars. But if I use it with my web project, with the same configurations, I get the same net.sf.cglib.proxy..... exception, I suspect some cross jar inconsistencies. How do we go about resolving such inconsistencies? is there any easy way apart from checking jars one at a time and figuring out the inconsistencies? I have checked my web projects classpath, they do not have any other cglib jars in the classpath.
-
Sep 19th, 2012, 03:24 AM
#6
I really hope you are using maven or gradle to manage your dependencies (or another dependency management tool) and aren't trying to put together things yourself! There must be cglib somewhere (maybe repacked but it must be somewhere) also as mentioned before make sure you don't have it in another classloader (somewhere in your server for instance)...
-
Sep 19th, 2012, 03:39 AM
#7
Thanks Marten for everything.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules