0 Replies Latest reply on Mar 9, 2005 8:07 AM by Tomoiaga Andreea

    JBoss AOP & Threads

    Tomoiaga Andreea Newbie

      I have written a logging aspect which has to log the execution of a method. This method is called in a new thread. When tested, logging occurs in the current thread only.

      aop
      aspect class="ExecutionLoggingAspect"/
      bind pointcut="call(void BaseNodeHandler->execute(Token))"
      advice name="logStartExitExecution" aspect="ExecutionLoggingAspect"/
      /bind
      bind pointcut="execution(* BaseNodeHandler->executeSpecific(Token))"
      advice name="logSpecificExecution" aspect="ExecutionLoggingAspect"/
      /bind
      /aop

      The execute() method :

      public void execute(Token token) {
      ...
      List targetNodeInstances = executeSpecific(token);

      //for each target node instance create a new Thread and start it.
      for (NodeInstance targetNodeInstance : targetNodeInstances) {
      NodeHandler handler = manager.getNodeHandler(targetNodeInstance);
      Thread nodeThread = new Thread(new NodeRunnable(token, handler));
      nodeThread.start();
      }
      ...
      }

      NodeRunnable.run() contains a call to BaseNodeHandler.execute() method. When currentHandler.execute() is called in a main() method, the advices of the ExecutionLoggingAspect are applied for the thread of the current handler but not for its child threads. What is wrong with the code?

      Thank you for any suggestion :)