您的位置:首页 > 编程语言 > Java开发

Java的动态编译 cglib / asm 等

2010-06-20 03:32 323 查看
http://www.qqread.com/netbase/w478517.html

菜鸟课堂:几个动态代理Proxy工具性能比较

JDK 6和CGLib cglib-nodep-2.2.jar对比结果:

JDK Proxy: 1,049,937 calls/s

CGLIB: 2,820,130 calls/s

如果使用cglib以前版本,性能更快:

JDK Proxy: 1,037,575 calls/s

CGLIB: 3,112,727 calls/s

而JDK 6和JavaAssit 3.11测试结果如下:

JDK Proxy: 1,037,575 calls/s

JAVAASSIST: 626,695 calls/s

从数据上看,cglib性能最好。但是和ASM、直接调用比较还不知道。

代码Object o = null;
try {
Class clazz0 = Class.forName("demo.cglib.ManagelogVO");

FastClass clazz = FastClass.create(clazz0);
o = clazz.newInstance();
FastMethod setterMethod = null;
FastMethod getterMethod = null;
Object v = null;

setterMethod = clazz.getMethod("setLogid", new Class[]{Long.class});
getterMethod = clazz.getMethod("getLogid", null);
v = getterMethod.invoke(managelogVO, new Object[]{});
setterMethod.invoke(o, new Object[]{v});

setterMethod = clazz.getMethod("setOprcode", new Class[]{String.class});
getterMethod = clazz.getMethod("getOprcode", null);
v = getterMethod.invoke(managelogVO, new Object[]{});
setterMethod.invoke(o, new Object[]{v});

---------------------------

http://www.ibm.com/developerworks/cn/java/j-lo-asm30/index.html

使用asm实现AOP

http://www.oschina.net/bbs/thread/4239

cglib的例子
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: