SCEA之路--7. EJB CONTAINER MODEL

本文介绍了EJB的生命周期,包括客户端定位、创建EJBObject等步骤。还阐述了EJB容器如何管理生命周期以提高可扩展性,如预先实例化bean池,客户端调用时从池中获取实例,使用完后放回,减少实例化开销。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

The Lifecycle of an EJB
Detailed documentation describing the lifecycle of an EJB can be found in the EJB specifications on the Sun web site and is llustrated in Figure 7-10. The following list provides a general description of the lifecycle states of an EJB session bean: 1. The client locates the bean’s home reference using the JNDI services provided by the application server.
2. The JNDI service returns a home interface reference to the client.
3. The client uses the home interface reference to call the home.create() method. In response, the home object then creates an JBObject. A new instance of the code in the bean class is also instantiated by the newInstance() method.
4. The new instance of the bean class, called a session bean, is allocated a session context.
5. The home object passes a reference to the EJBObject in the container to the client’s remote interface.
6. The client’s remote interface is now able to invoke methods on the EJBObject in the container. This EJBObject will pass these method calls to the session bean.
7. The session bean returns a result to the EJBObject, which in turn returns it to the client’s remote interface.

How the EJB Container Manages Lifecycle and How This Allows for Increased Scalability

1. The container populates the free pool with a working set of bean instances.
2. A client calls the create() method on a home object.
3. The home object obtains a bean instance from the free pool.
4. The home object forwards the create() arguments (if any) to the ejbCreate() method on the bean class.
5. The bean class inserts a row into the table in the database.
6. The bean class returns the primary key of the row to the home object.
7. The container creates an EJB object for the bean class and sets its primary key.
8. The home object invokes the ejbPostCreate() method on the bean class to finish the initialization process now that the EJB object can be referenced, because it now exists.
9. The home object returns the remote reference to the EJB object back to the client.
10. The client can now invoke the business methods on the bean class (via the remote reference) that have been defined as available.
11. When the client is finished, the container moves the bean back to the free pool list after calling ejbPassivate (for an entity bean).

Note that a substantial overhead is incurred when instantiating bean instances. Scalability within the EJB container environment is increased by preinstantiating a pool of bean instances (bean pool) and allowing them to be quickly utilized by clients.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值