java 实例化PortableRemoteObject笔记

之前获取Bean实例都是new,spring context,class.newInstance。今天阅读发现一种新的实例方法。

该方法有如下优点:

1、对实例化作check 

2、支持远程interface,abstract

 

此处为官方解释:

Server implementation objects may either inherit from javax.rmi.PortableRemoteObject or they may implement a remote interface and then use the exportObject method to register themselves as a server object. The toStub method takes a server implementation and returns a stub that can be used to access that server object. The connect method makes a Remote object ready for remote communication. The unexportObject method is used to deregister a server object, allowing it to become available for garbage collection. The narrow method takes an object reference or abstract interface type and attempts to narrow it to conform to the given interface. If the operation is successful the result will be an object of the specified type, otherwise an exception will be thrown.

 

该类可执行方法有:

static void connect(Remote target, Remote source)
Makes a Remote object ready for remote communication.
 

static void exportObject(Remote obj)
Makes a server object ready to receive remote calls.
 

static Object narrow(Object narrowFrom, Class narrowTo)
Checks to ensure that an object of a remote or abstract interface type can be cast to a desired type.
 

static Remote toStub(Remote obj)
Returns a stub for the given server object.
 

static void unexportObject(Remote obj)
Deregisters a server object from the runtime, allowing the object to become available for garbage collection.

 

具体执行方法为PortableRemoteObject.narrow(Object narrowFrom, Class narrowTo);返回一个实例的对象。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值