Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use EJB to achieve singleton mode

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use EJB to achieve the singleton model, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

How to use EJB to achieve singleton mode

Singleton pattern is a very useful design pattern in software engineering.

Simply put, singleton is an instance of a class that has only one global entry.

Typically, you will use the static reserved word to create when you define a class in Java

A singleton. However, one of the limitations of EJB is that it cannot be found in your

Fields in bean that use static. This hinders the use of singleton mode

Use it. 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

Simulates singleton mode. If all your objects know that in a JNDI tree

A single, well-known location in which a specific object is kept

They will effectively treat that object as a separate instance. Can you

This is done by binding a Rmi_IIOP stub to a JNDI tree.

Any client code will get a copy of that remote stub, and

Each copy will refer back to the same RMI-IIOP server object.

The drawback of this model is that you leave the EJB sandbox and downgrade to pass

RMI-IIOP, and you have lost all the services provided by EJB.

Thank you for reading this article carefully. I hope the article "how to use EJB to achieve singleton mode" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 289

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report