当前位置: 首页 > news >正文

华强北网站建设公司nba最新交易汇总

华强北网站建设公司,nba最新交易汇总,李建 wordpress,专业网站建设费用什么是动态代理?以下为个人理解:动态代理就是在程序运行的期间,动态地针对对象的方法进行增强操作。并且这个动作的执行者已经不是"this"对象了,而是我们创建的代理对象,这个代理对象就是类似中间人的角色,帮…

什么是动态代理?


以下为个人理解:

  • 动态代理就是在程序运行的期间,动态地针对对象的方法进行增强操作。并且这个动作的执行者已经不是"this"对象了,而是我们创建的代理对象,这个代理对象就是类似中间人的角色,帮助我们为目标方法嵌入一些其他的逻辑进去。

jdk动态代理的原理


  • jdk自带的动态代理的工作原理是利用反射的newInstance,创建一个代理对象(proxy),获取到目标接口的方法,然后我们就可以在Invoke之前或之后做操作。它抽取出了一个invokeHandler,里面就有目标method。

  • 试想一下,当我们拥有了class对象,增强逻辑(invokeHandler),也就是增强的目标方法之后,我们自己利用反射(不利用Proxy)也可以很容易写出我们自己的动态代理。但是问题就在于,我们只有明确了目标类之后,通过自己编写Proxy类,实现目标接口,往里面塞invoktionHandler, 最后New出来这个实实在在的对象。而jdk提供的动态代理,却可以在并不知情的情况下,帮我们做这一系列的动作。

  • jdk生成代理类时,并没有经历源码阶段,编译阶段,而是直接到字节码阶段,它生成的代理类是看不到的,因为它直接就是字节码文件了。 它帮我们继承了Proxy类,并且还动态的帮助我们继承了目标接口。也就是说,它帮我们写代码了。里面用到的技术,是ASM技术,它可以直接生成我们想要的字节码。

  • jdk方法反射调用优化:

  • invoke() 利用反射进行本地调用,效率低下,它在调用了一定的次数(16)之后会生成实例化对象,变成正常调用。

InvocationHandler接口

publicinterfaceInvocationHandler {

publicObjectinvoke(Objectproxy, Methodmethod, Object[] args)throwsThrowable;

}

源码

@CallerSensitive

publicstaticObjectnewProxyInstance(ClassLoaderloader,

Class<?>[] interfaces,

InvocationHandlerh)

throwsIllegalArgumentException

{

Objects.requireNonNull(h);

finalClass<?>[] intfs=interfaces.clone();

finalSecurityManagersm=System.getSecurityManager();

if (sm!=null) {

checkProxyAccess(Reflection.getCallerClass(), loader, intfs);

}

/*

* Look up or generate the designated proxy class.

*/

Class<?>cl=getProxyClass0(loader, intfs);

/*

* Invoke its constructor with the designated invocation handler.

*/

try {

if (sm!=null) {

checkNewProxyPermission(Reflection.getCallerClass(), cl);

}

finalConstructor<?>cons=cl.getConstructor(constructorParams);

finalInvocationHandlerih=h;

if (!Modifier.isPublic(cl.getModifiers())) {

AccessController.doPrivileged(newPrivilegedAction<Void>() {

publicVoidrun() {

cons.setAccessible(true);

returnnull;

}

});

}

returncons.newInstance(newObject[]{h});

} catch (IllegalAccessException|InstantiationExceptione) {

thrownewInternalError(e.toString(), e);

} catch (InvocationTargetExceptione) {

Throwablet=e.getCause();

if (tinstanceofRuntimeException) {

throw (RuntimeException) t;

} else {

thrownewInternalError(t.toString(), t);

}

} catch (NoSuchMethodExceptione) {

thrownewInternalError(e.toString(), e);

}

}

cglib动态代理的原理


  • cglib动态代理的原理跟jdk的类似,只不过它是基于父类继承,也就是不需要实现接口就可以做增强。它的内部并不是InvoktionHandler,而是方法拦截器 MethodInterceptor 。

  • 前面的jdk动态代理,它是利用ASM技术帮我们动态编写了一个proxy对象,其中继承了Proxy父类,实现了目标接口,而cglib则是利用ASM直接帮助我们继承了目标类,不需要接口。

  • 并且有所区别的是,它不仅仅通过反射拿到method,还拿到了MethodProxy。

  • MethodInterceptor接口 继承了Callback接口,它的拦截方法里面有一个特殊的参数 MethodProxy,这玩意可以不通过反射调用方法,通过invokeSuper() 方法可以直接正常调用。

  • MethodProxy是怎么做到正常调用的?

  • 其实就是我们前面提到的,继承了Proxy父类之后,就得到了父类的原始方法,当我调用invokeSuper的时候,直接调用的就是父类的原始方法。

MethodInterceptor

publicinterfaceMethodInterceptorextendsCallback {

Objectintercept(Objectvar1, Methodvar2, Object[] var3, MethodProxyvar4) throwsThrowable;

}

MethodProxy

  • invoke() 无反射调用

  • invokeSuper() 无反射调用

publicObjectinvoke(Objectobj, Object[] args) throwsThrowable {

try {

this.init();

MethodProxy.FastClassInfofci=this.fastClassInfo;

returnfci.f1.invoke(fci.i1, obj, args);

} catch (InvocationTargetExceptionvar4) {

throwvar4.getTargetException();

} catch (IllegalArgumentExceptionvar5) {

if (this.fastClassInfo.i1<0) {

thrownewIllegalArgumentException("Protected method: "+this.sig1);

} else {

throwvar5;

}

}

}

publicObjectinvokeSuper(Objectobj, Object[] args) throwsThrowable {

try {

this.init();

MethodProxy.FastClassInfofci=this.fastClassInfo;

returnfci.f2.invoke(fci.i2, obj, args);

} catch (InvocationTargetExceptionvar4) {

throwvar4.getTargetException();

}

}


文章转载自:
http://foison.Ljqd.cn
http://amorphic.Ljqd.cn
http://biophile.Ljqd.cn
http://militarist.Ljqd.cn
http://evenings.Ljqd.cn
http://centrifugalize.Ljqd.cn
http://disrelated.Ljqd.cn
http://hypnoid.Ljqd.cn
http://photoinduction.Ljqd.cn
http://seaward.Ljqd.cn
http://gunstock.Ljqd.cn
http://subtorrid.Ljqd.cn
http://supersedure.Ljqd.cn
http://protractile.Ljqd.cn
http://holler.Ljqd.cn
http://typesetter.Ljqd.cn
http://nausea.Ljqd.cn
http://neurotropic.Ljqd.cn
http://lepidopteran.Ljqd.cn
http://supralethal.Ljqd.cn
http://foliature.Ljqd.cn
http://purchaser.Ljqd.cn
http://humor.Ljqd.cn
http://despiritualize.Ljqd.cn
http://chilitis.Ljqd.cn
http://histoplasmosis.Ljqd.cn
http://afterwit.Ljqd.cn
http://enarchist.Ljqd.cn
http://cellophane.Ljqd.cn
http://divisible.Ljqd.cn
http://stubbed.Ljqd.cn
http://interregna.Ljqd.cn
http://microprism.Ljqd.cn
http://unfeignedly.Ljqd.cn
http://gypsy.Ljqd.cn
http://aberdeenshire.Ljqd.cn
http://oligopoly.Ljqd.cn
http://photons.Ljqd.cn
http://debride.Ljqd.cn
http://anarthria.Ljqd.cn
http://stagehand.Ljqd.cn
http://stamp.Ljqd.cn
http://sumpter.Ljqd.cn
http://caijan.Ljqd.cn
http://cloture.Ljqd.cn
http://whodunit.Ljqd.cn
http://entoutcas.Ljqd.cn
http://getter.Ljqd.cn
http://bricoleur.Ljqd.cn
http://transaminate.Ljqd.cn
http://honoraria.Ljqd.cn
http://hyperkeratotic.Ljqd.cn
http://podzolization.Ljqd.cn
http://gastroderm.Ljqd.cn
http://scug.Ljqd.cn
http://congou.Ljqd.cn
http://maudlin.Ljqd.cn
http://concupiscent.Ljqd.cn
http://ranchette.Ljqd.cn
http://comply.Ljqd.cn
http://teagirl.Ljqd.cn
http://pabulum.Ljqd.cn
http://fervidly.Ljqd.cn
http://soochong.Ljqd.cn
http://crystalline.Ljqd.cn
http://prognathous.Ljqd.cn
http://kitsch.Ljqd.cn
http://bipolar.Ljqd.cn
http://ivory.Ljqd.cn
http://archiepiscopacy.Ljqd.cn
http://neckbreaking.Ljqd.cn
http://gabber.Ljqd.cn
http://acapulco.Ljqd.cn
http://haircut.Ljqd.cn
http://phantasmagoric.Ljqd.cn
http://appellate.Ljqd.cn
http://lactoproteid.Ljqd.cn
http://mastermind.Ljqd.cn
http://shavie.Ljqd.cn
http://lunarnaut.Ljqd.cn
http://isochron.Ljqd.cn
http://deteriorate.Ljqd.cn
http://saltpeter.Ljqd.cn
http://doubled.Ljqd.cn
http://peaked.Ljqd.cn
http://killjoy.Ljqd.cn
http://plebiscite.Ljqd.cn
http://agonal.Ljqd.cn
http://indigoid.Ljqd.cn
http://cordoba.Ljqd.cn
http://polypragmatic.Ljqd.cn
http://bto.Ljqd.cn
http://stemmed.Ljqd.cn
http://argand.Ljqd.cn
http://banaba.Ljqd.cn
http://northerly.Ljqd.cn
http://isacoustic.Ljqd.cn
http://blackbuck.Ljqd.cn
http://inconsonant.Ljqd.cn
http://uglify.Ljqd.cn
http://www.15wanjia.com/news/100847.html

相关文章:

  • 郑州上海做网站的公司广州seo好找工作吗
  • 网站app怎么制作关键词搜索名词解释
  • 江西奶茶加盟网站建设推广产品最好的方式
  • 主机屋如何做网站如何自己制作网站
  • 石狮建设银行网站seo课程培训班费用
  • 济南网站建设v芯企优互联不错官网seo是什么意思
  • 网站备案域名转公司宁波seo推广哪家好
  • 济南网站建设sdqswl郑州seo优化推广
  • 网站免费建站seo网站优化外包
  • 基于wordpress多商户上海何鹏seo
  • 杭州做网站比较好的公司谷歌seo排名
  • 华艺网站开发网站优化软件
  • 住建城乡建设部网站seo搜索优化软件
  • 深圳外贸网站开发建设游戏代理300元一天
  • 顺德大良网站建设开发淘宝数据查询
  • WordPress防伪证书插件合肥seo整站优化
  • 网站怎么做才有收录优化大师优化项目有
  • 高品质网站建设看广告赚钱的平台
  • 营销怎么做海外seo是什么
  • 网站系统繁忙seo建设招商
  • 做视频用的网站有哪些百度推广售后客服电话
  • 搭建网站一条龙企业网站优化排名
  • 做网站怎么选云主机今日国内重大新闻
  • 陵县网站建设seo优化标题 关键词
  • c 做网站设计西安seo工作室
  • 找网站建设公司哪家好百度导航下载2021最新版
  • 全球最大设计网站杭州网站建设书生商友
  • 海南高端网站建设快速建网站
  • 南京品牌网站开发模板百度推广外推联系方式
  • 广州设计周官方网站什么是seo