Announcement Announcement Module
No announcement yet.
Help @Async not working! Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help @Async not working!


    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 {

    public void asyncDeploy(final long userId, final long jobId, final String deployerXml) {
    System.out.println("Started processing the Job: " + jobId);
    // TODO: process xml
    System.out.println("Finished processing the Job: " + jobId);


    private void deploy() {
    try {
    } catch (InterruptedException e) {
    log.warning("Thread interrrupeted");


    Test Class: -

    @ContextConfiguration(locations = {"application.xml"})
    public class DeployerHelperTest extends TestCase {

    private DeployerHelper deployerHelper;

    public void setup() {

    public void asyncDeploy() {
    System.out.println("**** Start: Deployer Async ****");
    deployerHelper.asyncDeploy(1, 1, "TET");
    System.out.println("**** End: Deployer Async ****");
    try {
    } catch (InterruptedException e) {
    // TODO Auto-generated catch block

    public void setDeployerHelper(DeployerHelper helper) {
    this.deployerHelper = helper;

    application xml : -

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans xmlns=""
    xsi:schemaLocation="" default-autowire="byName">

    <beans:bean id="deployerHelper" class="com.newscale.comps.supportability.controlle r.DeployerHelper">
    <beansroperty name="logDirPath" value="Deployer/logs" />

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


  • #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...


    • #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?


      • #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.


        • #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.


          • #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)...


            • #7
              Thanks Marten for everything.