I need to get Thread names and log them in AspectJ class. This solution does’t work
`@Around("call(void method*())")
public Object condition(ProceedingJoinPoint joinPoint) throws Throwable
{
PropertyConfigurator.configure("log4j.properties");
long before = System.currentTimeMillis();
Object res = joinPoint.proceed();
long diff = System.currentTimeMillis() - before;
logger.info(Thread.currentThread().getName() + "\t" + diff );
return res;
}
`
because the result is e.g.:
main 717
My aspect is around some methods. How to get name of thread where method is executed (not thread created by aspect)?
1. First of all its Not the thread where method is execute, But the thread that executes the method.
2. Here what you can do to identify the thread that executed that method:
– Initialize the thread.
// MyClass is the class which extends or implements Thread or Runnable respectively.
– Naming the thread of execution.
– Inside the method getting the thread that is executing it.