trhouse | 9 Feb 23:09
Picon

Capturing join points based on thread

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.
Andy Clement | 10 Feb 19:38
Picon

Re: 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();
		}
	}

(Continue reading)


Gmane