spring rmi代理性能

在看spring为rmi提供的export机制时看到 RmiBasedExporter 这个类,当我们在开发rmi调用服务接口并不需要实现Remote接口,Spring在启动的时候会为服务接口对象自动生成代理对象(RmiInvocationWrapper),这个代理类本身实现了Remote接口。通过查看代理对象的源代码发现,在代理对象中是通过反射机制来调用业务service的,我们知道反射机制比非反射机制的调用的效率慢不少。所以我想是不是能让业务业务服务接口继承Remote接口,这样spring在启动服务的时候就不需要为服务对象生成rmi的代理了。说不定这样效率会提高不少哦!

不过这样的改造之后,需要接口方法显示地抛出RemotingException,这样对客户端来说稍微有些麻烦。

public abstract class RmiBasedExporter extends RemoteInvocationBasedExporter { protected Remote getObjectToExport() { // determine remote object if (getService() instanceof Remote && ((getServiceInterface() == null) || Remote.class.isAssignableFrom(getServiceInterface()))) { // conventional RMI service return (Remote) getService();} else { // RMI invoker if (logger.isDebugEnabled()) { logger.debug("RMI service [" + getService() + "] is an RMI invoker"); } return new RmiInvocationWrapper(getProxyForService(), this); } } /** * Redefined here to be visible to RmiInvocationWrapper. * Simply delegates to the corresponding superclass method. */ protected Object invoke(RemoteInvocation invocation, Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { return super.invoke(invocation, targetObject); } }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值