Results 1 to 7 of 7

Thread: Help @Async not working!

  1. #1
    Join Date
    Jul 2009
    Location
    Bangalore
    Posts
    7

    Exclamation 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">
    <beansroperty name="logDirPath" value="Deployer/logs" />
    </beans:bean>

    <task:executor id="threadPoolTaskExecutor" pool-size="10" />

    </beans:beans>

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jul 2009
    Location
    Bangalore
    Posts
    7

    Default

    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?

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Jul 2009
    Location
    Bangalore
    Posts
    7

    Default

    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.

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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)...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  7. #7
    Join Date
    Jul 2009
    Location
    Bangalore
    Posts
    7

    Default

    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
  •