使用JNDI在多个JVM上单例 [英] Singleton on multiple JVMs using JNDI

查看:155
本文介绍了使用JNDI在多个JVM上单例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据说Singleton始终基于每个JVM,但是有人要求我在多个JVM中创建一个Singleton实例。我找到了一种解决方案,可以在一个JVM上创建对象,向JNDI注册该对象,然后在不同的JVM上查找该对象。

It is said that Singleton is always on per JVM basis, but somebody asked me to create a singleton instance throughout multiple JVMs. I have found a solution to create an object on one JVM, register it with the JNDI, and lookup that object on different JVMs.

请分享您对此的见解。 / p>

Please share your insight on this.

推荐答案

我的见解是它不起作用。

My insight is that it won't work.

甚至如果您使用JNDI查找单例然后再使用它,则单例也将有效地在您使用的JVM上创建。

Even if you lookup the singleton using JNDI and then use it, the singleton will effectively be created on the JVM you are using as well.

唯一的方法是仅在该单例豆远程。可能是通过RMI之类的。

Only way is to just invoke methods on that singleton bean remotely. May be via something like RMI.

这篇关于使用JNDI在多个JVM上单例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆