« Return to Thread: Pointcut scoped variables

Pointcut scoped variables

by jbx :: Rate this Message:

Reply to Author | View in Thread

Is there a way to have "point-cut joinpoint scoped" variables shared across @Before advices and @After advices (for the same joinpoint instance)?

Consider the following simple example, just to illustrate the case. Imagine it is running in a multi-threading application:

public void doTask(TheTask task)
{
   //these two lines should be in a separate aspect @Before the pointcut for this method
   String oldname = Thread.currentThread().getName();
   Thread.currentThread().setName(task.getName());

   try
   {
       //do the actual task
       task.execute();
    }
    finally
    {
       //the following should be in a separate aspect @After the pointcut for this method
       Thread.currentThread().setName(oldname);
    }
}


How do I carry the oldname variable for the same joinpoint, from one advice to another (in the same pointcut scope), if at all possible?

Thanks.

 « Return to Thread: Pointcut scoped variables