AppDynamics Application Intelligence Platform
3.9.x Documentation
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.
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
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
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:
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