RMI 公开的 jBoss EJB 上的并发远程调用是否已序列化?
这是同一问题的更详细版本昨天问过。
我有一个客户端应用程序,它通过对无状态 EJB 的 RMI 调用与服务器应用程序进行通信。使用这些配置参数构建初始上下文:
InitialContext ctx = new InitialContext(new Hashtable<String, String>() {
{
this.put("java.naming.provider.url", "serverUrl:portNumber");
this.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
this.put("java.naming.factory.url", "org.jnp.interfaces.TimedSocketFactory");
}
});
然后使用以下方式查找代理:
ServerBean bean = (ServerBean) ctx.lookup("ejb/ServerBeanImpl");
然后客户端生成许多共享 ServerBean
的同一实例的线程。每个线程时不时地对共享 bean 进行远程调用。
我的问题是,这些调用是以串行还是并行方式执行的?每个远程调用都在服务器上执行。执行一些计算并返回结果。如果所有调用都被序列化,那么我将不得不限制现有线程的数量,因为其中许多线程可能会在 ServerBean
上被阻止。
This is a more detailed version of the same question asked yesterday.
I have a client app which communicates with the server app through RMI calls to stateless EJBs. The initial context is being built with these config params:
InitialContext ctx = new InitialContext(new Hashtable<String, String>() {
{
this.put("java.naming.provider.url", "serverUrl:portNumber");
this.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
this.put("java.naming.factory.url", "org.jnp.interfaces.TimedSocketFactory");
}
});
A proxy is then looked up using:
ServerBean bean = (ServerBean) ctx.lookup("ejb/ServerBeanImpl");
Client then spawns many threads sharing this same instance of the ServerBean
. Every thread now and then invokes remote calls on the shared bean.
My question is, are these calls performed in a serial or parallel manner? Every remote call is executed on the server. Some computing is performed and a result is returned. If all calls are serialized then I'll have to limit the number of existing threads since many of them can be blocked on the ServerBean
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
调用至少会被服务器端的容器阻塞。但请注意,几乎所有应用程序服务器都有线程池来限制请求数量,因此无状态 Bean 池大小为 1000 且服务器线程池大小为 100 没有什么好处——无状态 Bean 池永远不会增长到超过 100。
所以要检查的是:
如果没有客户端连接池并且所有线程共享相同的连接,那么除非在客户端/服务器之间使用 NIO,否则您将受到很大限制。
如果目标只是并行执行操作,我会使用 EJB 3.1 @Asynchronous 方法支持,它支持 @Remote 调用。这将为您提供最大的并发性和最可移植性,而不必担心限制您自己的使用。
The calls will be blocked by the container on the server side at the very least. But beware that nearly all app servers have thread pools to limit the number of requests, so having a stateless bean pool size of 1000 and a server thread pool size of 100 does you little good -- your stateless bean pool will never grow past 100.
So the things to check are:
If there is no client-side connection pool and all threads share the same connection, you're pretty much limited right there unless NIO is used between client/server.
If the goal is to just do things in parallel, I'd use the EJB 3.1 @Asynchronous method support which does support @Remote calls. That will give you the most concurrency the most portably without having to worry about throttling your own usage.
我认为如果您想要异步行为,那么使用 MDB/MDP 是您想要的方式。
I'm thinking using MDBs/MDPs is the way you want to go if you want Asynchronous behaviour.