[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Capturing join points based on thread
|
You can use the thread information but only in an if() clause. Here
is an example program that selectively applies to joinpoints on a
thread:
===
aspect X {
before(): call(* foo(..)) &&
if(Thread.currentThread().getName().equals("two")) {
System.out.println("Intercepted call to foo on thread 'two'");
}
}
public class Flibble {
public static void main(String[] args) {
Thread s = new Thread(new MyRunnable(),"one");
Thread t = new Thread(new MyRunnable(),"two");
s.start();
t.start();
}
}
class MyRunnable implements Runnable {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
foo();
}
}
public void foo() {
System.out.println("foo on "+Thread.currentThread().getName());
}
}
===
But that will insert a lot of checks on the thread around the calls.
Actually you may be able to do something using threadlocals too -
perhaps a threadlocal is only set for the threads you are interested
in then you query that in your advice.
cheers,
Andy
On 9 February 2012 14:09, trhouse <trhouse@xxxxxxxxx> wrote:
> Hi all,
> I want to exclude join points based on the thread.
>
>
> Example. I want to capture all method calls on class Foo unless those
> methods were being executed on thread X.
>
> Is this possible?
>
> Thank you.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users