Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] pointcut before thread exits

Hi,

In order to weave this:

public final pointcut allThreadRun(Thread t) : execution(void run())
&& this(t) && !within(ProfilerAspect);

AspectJ would need to be able to weave the Thread class - it cannot do
that easily.  You could extend Thread with a subtype I suppose, but
instead what you can do is detect that your Runnable is about to
finish and determine the Thread at that point:

public final pointcut allThreadRun(Runnable r) : execution(void run())
&& this(r) && !within(ProfilerAspect);

after(Runnable r) : allThreadRun(r) {
  Thread threadThatIsEnding = Thread.currentThread();
  threadStopHash.put(threadThatIsEnding,System.currentTimeMillis());
}

Andy

On 6 November 2010 12:03, Ajendrex <ajendrex@xxxxxxxxx> wrote:
>
> Hello,
>
> I need to get the time in which every program's thread exits. The code I am
> profiling looks like this:
>
> public class Phil implements Runnable {
>           Phil() {     // constructor
>              new Thread(this, "Phil").start(); // make a new thread and start it
>           }
>
>           public void run() {                  // must override run, this is what
>              for(int i=0; i<2;) {              // is executed when the thread starts running
>                   if(<TEST SOMETHING>)
>                      i++;
>                   Thread.sleep(500);
>              }
>           }
>
> Anyway, the idea is to have a profiler that would trace any code, so the
> solution has to be general.
>
> my try has been:
>
> public final pointcut allThreadRun(Thread t) : (execution(void run()) &&
> this(t) && !within(ProfilerAspect);
>
> after(Thread t) : allThreadRun(t) //!the advice doesn't match anything, the
> following code never executes
> {
>    threadStopHash.put(t,System.currentTimeMillis());
> }
>
> Any info will be appreciated.
>
> Thanks!
>
> Hector.
> --
> View this message in context: http://aspectj.2085585.n4.nabble.com/pointcut-before-thread-exits-tp3030282p3030282.html
> Sent from the AspectJ - users mailing list archive at Nabble.com.
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>


Back to the top