AppDynamics Application Intelligence Platform

3.9.x Documentation

PDFs

Learn by Watching

Doc Maps

Skip to end of metadata
Go to start of metadata

Java 8 includes a many new features, most notably there are several new language constructs: lambdas, static interface methods, and default interface methods. This document helps you instrument these constructs.

Language Constructs

Lambdas

Lambdas are a new addition to Java 8, enabling a functional style of programming in Java. Here's a short example:

LambdaMethodInterface i = (acc, x) -> acc + x;

In the JVM, this essentially creates an anonymous instance of the associated FunctionalInterface, shown below:

package jdk8;
 
@java.lang.FunctionalInterface
interface LambdaMethodInterface
{
    int sum(int acc, int x);
}

To instrument lambda instances, create a POJO business transaction match rule for the LambdaMethodInterface such as:

Match Classes      that implements an interface which      Equals      jdk8.LambdaMethodInterface

Interface Static Methods

Interfaces now can have static methods, such as can be found in the example below:

package jdk8;

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

 

The bytecode for this construct resides in the compiled class file so a class match against the interface class will instrument that class for a business transaction.

Create a POJO business transaction match rule for the interfaceForStaticMethod such as:

Match Classes      with a Class Name that      Equals      jdk8.InterfaceForStaticMethod 

Interface Default Methods

Interfaces can now have default methods. As with interface static methods, the bytecode resides in the interface for default methods.

There are two important points to keep in mind when defining instrumentation against an interface default method:

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

Instrumenting an Interface Default Method Directly

Given:

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

And:

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:

Match Classes      with a Class Name that      Equals      jdk8.InterfaceForConcreteClassDefaultMethod


 

Instrumenting an Overridden Default Method

Given:

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:

Match Classes      with a Class Name that      Equals      jdk8.InterfaceForAnonymousClassDefaultMethod

 

 

  • No labels