[ajug-members] AspectJ question
Dan Marchant
driedtoast at gmail.com
Thu Sep 7 13:00:00 EDT 2006
No problem...
Good to see people using aspectj for things.
Great addition to a project if used right.
- Dan
On 9/7/06, Brian Lee <brian_a_lee at hotmail.com> wrote:
> Thanks Dan, this is just what I'm looking for but I missed the around advice
> and only saw before and after.
>
> I'll implement something like this.
>
> BAL
>
> >From: "Dan Marchant" <driedtoast at gmail.com>
> >Reply-To: "General AJUG membership forum (100-200
> >messages/month)"<ajug-members at ajug.org>
> >To: "General AJUG membership forum (100-200
> >messages/month)"<ajug-members at ajug.org>
> >Subject: Re: [ajug-members] AspectJ question
> >Date: Thu, 7 Sep 2006 06:52:15 -0400
> >
> >What you are looking for is around.
> >
> >public aspect PerformanceAspect {
> > pointcut largeMethods(int i): call(* get*(..)) && args(i);
> > Logger log = Logger.getLogger("PerformanceAspect");
> >
> > Object around(int i): largeMethods(i) {
> > long start = System.currentTimeMillis();
> > Object obj = proceed(i*2);
> > long end = System.currentTimeMillis();
> > Signature sig = thisJoinPointStaticPart.getSignature();
> >
> > log.info(sig.toString() + "Time took: " + (end-start));
> >
> > return obj;
> > }
> > }
> >
> >
> >Hope this helps. Obviously this sets out an example you can use.
> >Look for Around Advice within the AspectJ docs.
> >
> >- Dan
> >
> >On 9/6/06, Brian Lee <brian_a_lee at hotmail.com> wrote:
> >>Hello all,
> >>
> >>I am looking at using AspectJ for my Java 1.4 project. I was going through
> >>the online docs and googled around, but couldn't find any examples of an
> >>aspect class that is able to capture performance times for method calls.
> >>
> >>I would like to add a performance aspect to a set of methods so that I
> >>output a log statement with the total time spent before and after the
> >>method
> >>is executed.
> >>
> >>I saw a lot of examples of before and after join points, but not one that
> >>could introduce a local long variable to store the currentTimeMillis
> >>before
> >>and after the method executes.
> >>
> >>Has anyone else used aspects for this kind of performance logging? Any
> >>help
> >>is appreciated.
> >>
> >>Thanks,
> >>BAL
> >>
> >>
> >>_______________________________________________
> >>ajug-members mailing list
> >>ajug-members at ajug.org
> >>http://www.ajug.org/mailman/listinfo/ajug-members
> >>
> >_______________________________________________
> >ajug-members mailing list
> >ajug-members at ajug.org
> >http://www.ajug.org/mailman/listinfo/ajug-members
>
>
> _______________________________________________
> ajug-members mailing list
> ajug-members at ajug.org
> http://www.ajug.org/mailman/listinfo/ajug-members
>
More information about the ajug-members
mailing list