异步Java RMI
最近我需要使用 RMI,并且我对我需要做什么已经足够了解,但是当我重新审视这个主题时,有一件事引起了我的兴趣。是否可以对服务器上的同一服务进行异步 RMI 调用?
假设我在客户端有 n 个线程和一个服务器端对象——称之为 S。S 有一个我想从客户端线程调用的方法,但我不希望它被阻塞无需担心共享资源。
有什么想法吗?或者这是最好留给其他方法的东西吗?
Recently I have needed to use RMI, and I know enough for what I need to do, but one thing is intriguing me as I revisit this topic. Is it possible to make asynchronous RMI calls to the same service on the server?
Let's say I have n threads on the client and a single server-side object--call it S. S has a single method that I want to call from my client-side threads, but I don't want it to block as it has no shared resource to worry about.
Any ideas? Or is this something that is just better left to other methods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这样做应该没有问题。从服务的角度来看,这相当于多个客户端同时调用同一个服务。
任何服务器端对象都应该编写为对于并发访问是安全的。
There should be no issues with doing this. It is the equivalent of multiple clients calling the same service at the same time from the service's perspective.
Any server side object should be written to be safe for concurrent access.
也许您应该使用 JMS 队列之类的东西来在 J2EE 架构上进行异步调用。在这些情况下它可以完美地工作。
Probably you should work with something like JMS queue for asynchronic calls on an J2EE architecture. It works perfectly in these cases.
使用 Redisson 框架远程服务可以在与客户端 Redisson 实例相同的节点上注册,甚至可以在与客户端 Redisson 实例共享的同一 JVM 上注册。
假设
YourServiceImpl
包含您需要远程调用的方法并实现YourService
接口。YourServiceImpl 应通过 RemoteService 对象在 Redisson 中注册:
远程调用可以以异步方式进行,并标记单独的接口
带有@RRemoteAsync注释。方法签名应与远程接口中的相同方法匹配。
每个方法都应该返回 org.redisson.core.RFuture 对象。它扩展了java.util.concurrent.Future
和 java.util.concurrent.CompletionStage 接口以及
有用的方法很少。
要远程调用方法,请使用
YourServiceAsync
接口:更多文档为 此处
Using Redisson framework remote service could be registered on same node with client side Redisson instance and even on same JVM shared with client side Redisson instance.
Let's assume
YourServiceImpl
contains method you need to invoke remotely and implementsYourService
interface.YourServiceImpl should be registered in Redisson via RemoteService object:
Remote invocations could be made in asynchronous manner with separate interface marked
with
@RRemoteAsync
annotation. Method signatures should be match with same methods in remote interface.Each method should return
org.redisson.core.RFuture
object. It extendsjava.util.concurrent.Future
and
java.util.concurrent.CompletionStage
interfaces andhas few useful methods.
To invoke method remotely use
YourServiceAsync
interface:More documentation is here