On this page:

Your Rating:
Results:
PatheticBadOKGoodOutstanding!
17 rates

As of Java 8, Java interfaces can include static and default methods. This topic describes how to monitor these types of interface methods.

 Note that another Java language feature introduced in Java 8, lambda method interfaces, are not supported by the AppDynamics Java Agent.  

Interface Static Methods

The following code snippet shows an example static interface method:

package jdk8;

interface InterfaceForStaticMethod
{
    static int sum(int acc, int x)
    {
        return acc + x;
    }
}


The actual bytecode for the method would reside in the compiled class file, so a class match against the interface class in the AppDynamics configuration would result in the instrumentation of that class for a business transaction.

To instrument such methods, create a POJO business transaction match rule for the interfaceForStaticMethod, such as:

In this case, the rule would match classes with a Class Name of jdk8.InterfaceForStaticMethod

Interface Default Methods

Interfaces can also define default methods. As with interface static methods, the bytecode for default methods resides in the compiled class files.

When configuring instrumentation for a default method, note these points:

  1. If the targets are classes that do not override the default method, target the interface via a class match 
  2. If the targets are classes that do override the default method, target the interface via an interface match

Instrumenting an Interface Default Method Directly

Given the following interface:

package jdk8;
 
interface InterfaceForConcreteClassDefaultMethod
{
    default int sum(int acc, int x)
    {
        return acc + x;
    }
}

And its implementing class:

package jdk8;

class ClassForDefaultMethod implements InterfaceForConcreteClassDefaultMethod
{
}

In this example, the ClassForDefaultMethod does not override the default method. Therefore, you can use a class match against the interface such as:

Instrumenting an Overridden Default Method

Given the following interface:

package jdk8;

interface InterfaceForAnonymousClassDefaultMethod
{
    default int sum(int acc, int x)
    {
        return acc + x;
    }
}

And:

InterfaceForAnonymousClassDefaultMethod i = new InterfaceForAnonymousClassDefaultMethod()
{
	@Override
	public int sum(int acc, int x)
	{
		return acc + x;
	}
};

Because the method is overridden, the target bytecode resides in the anonymous class, InterfaceForAnonymousClassDefaultMethod. So you need to create an interface match POJO business transaction match rule such as:

 

  • No labels