Maven 依赖
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.1</version>
</dependency>
虚拟机参数
-XX:MetaspaceSize=10M -XX:MaxMetaspaceSize=10M -verbose:class
Java 程序
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import java.lang.reflect.Method;
public class Permanent {
public static void main(String[] args) {
int i = 0;
while (true) {
System.out.println(i++);
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(Permanent.class);
enhancer.setUseCache(false);
enhancer.setCallback(
new MethodInterceptor() {
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
return methodProxy.invokeSuper(o, args);
}
}
);
enhancer.create();
}
}
}
网友评论