java - How to get a value from an @Around declared method using AspectJ? -
this code snippet:
@around("execution(* de.my.package.path.controller.recommendationcontroller.recommenditems*(..))") public object measuretimewithoverhead(proceedingjoinpoint joinpoint) throws throwable { long startnanotime = system.nanotime(); object proceed = joinpoint.proceed(); long endnanotime = system.nanotime(); long diff = endnanotime - startnanotime; system.out.println("elapsed time: " + (diff)); return proceed; }
i want use value of "diff" variable in further program. how can retrieve value? possible @ all?
(btw, working on spring 4.0.2 mvc application)
currently, no. diff
variable local variable , therefore accessible within body of method, after it's been declared (and initialized).
aop advice meant add additional behavior (by executing code) @ point in execution of program. it's self contained component. can know code it's intercepting, not vice-versa.
there work arounds if need this, but don't recommend it. can use static
threadlocal
in class , set value whatever diff
is. can access threadlocal
anywhere else.
Comments
Post a Comment