Reputation: 796
I have added @Profiled
annotation for public and private method. I can see the timing logs for public methods. But there is no timing logs for private methods.
I did the configurations correctly.
@Profiled
public BigInteger nextPrime() {
currentPrime = currentPrime.nextProbablePrime();
return currentPrime;
}
@Profiled
private void test()
{
try{
Thread.sleep(100);
}catch(Exception e)
{
e.printStackTrace();
}
}
Is @profiled annotation only applicable for only public methods?
Upvotes: 1
Views: 914
Reputation: 768
Yes. It is limitation of the Spring AOP:
When using proxies, you should apply the you annotations only to methods with public visibility. If you do annotate protected, private or package-visible methods with these annotations, no error is raised, but the annotated method does not exhibit the configured caching settings. Consider the use of AspectJ (see below) if you need to annotate non-public methods as it changes the bytecode itself.”
Upvotes: 0
Reputation: 64011
Most likely you have configured perf4j with Spring AOP and since Spring AOP proxies are not invoked when a method is called from inside the same class (as in your case with the test
method), no performance statistics will be recorded.
Check out this blog post which explains Spring AOP pitfalls
One solution to your problem would be to use AspectJ with perf4j, since AspectJ can handle this type of situation
Upvotes: 2