How to use EJB to achieve Singleton mode

zhaozj2021-02-11  186

How to use EJB to achieve Singleton mode Singleton mode is a very useful design pattern in software engineering, simple saying Singleton is an instance of a class with only a global entrance. Usually, you will use Static reserves when you define a class in Java to create a Singleton. However, a restriction of EJB is the field that cannot be used in your BEAN. This hinders the use of Singleton mode. But we still like to use Singleton mode, how to do it? The answer is JNDI. You can use JNDI to store arbitrary objects to simulate Singleton mode. If all your objects know a single, a famous location in a JNDI tree, where a specific object is saved, they will effectively treat the object as a separate instance. You can do this by binding a RMI_IIOP Stub to a JNDI tree. Any client code will get a copy of the remote stub, and each copy will refer to the same RMI-IIOP server object ... This mode is the disadvantage that you left the EJB sandbox and dropped by RMI-IIOP, and you Losing all EJB services provided.

转载请注明原文地址:https://www.9cbs.com/read-5230.html

New Post(0)