Created
April 25, 2020 16:30
-
-
Save sunwu51/dca198c8a4922d77a51a1b9e945b2f59 to your computer and use it in GitHub Desktop.
metaspace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package meta; | |
import org.springframework.cglib.proxy.Enhancer; | |
import org.springframework.cglib.proxy.MethodInterceptor; | |
import org.springframework.cglib.proxy.MethodProxy; | |
import java.lang.reflect.Method; | |
/** | |
* @author Frank | |
* @date 2020/4/25 23:32 | |
*/ | |
public class Main { | |
static class demo{ | |
} | |
//-XX:MetaspaceSize=10m -XX:MaxMetaspaceSize=10m -XX:+PrintGCDetails | |
public static void main(String[] args) { | |
while (true) { | |
Enhancer enhancer = new Enhancer(); | |
enhancer.setSuperclass(demo.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, objects); | |
} | |
}); | |
enhancer.create(); | |
} | |
} | |
// public static void main(String[] args) { | |
// System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true"); | |
// | |
// // jdk动态代理测试 | |
// Subject subject1 = new JDKDynamicProxy(new RealSubject()).getProxy(); | |
// Subject subject2 = new JDKDynamicProxy(new RealSubject2()).getProxy(); | |
// subject1.doSomething(); | |
// subject2.doSomething(); | |
// while (true){ | |
// Object i = new JDKDynamicProxy(new RealSubject()).getProxy(); | |
// } | |
// } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gclib动态代理类不断创建,导致metaspace溢出,OOM。下面jdk代理类并没有导致这个问题,因为一直都是Proxy0这个类,没有创建新的类。