敬的世界

常用链接

统计

最新评论

关于 EJB

Overview

EJB consists of a remote interface, a home interface and an EJBimplementation.  

The remote interface declares business methods that clients of the EJB may invoke. The remote interface must extend interface javax.ejb.EJBObject. The EJB container generates a class that implements the remote interface.

The home interface provides create methods for creating new EJB instances. finder methods for finding EJB instance and remove methods fro removing EJB instances. 

The EJB container provides the EJB's runtime environment and life-cycle management. 

What EJB Container does ?

 The EJB container manages an EJB's client interfactons, method invocations transactions security, exceptions, etc. Clients of an EJB do nnot interact directly with the EJB,Clients access the EJB container to obtain remote references to EJB instances.

The EJB container also manages the life cycles of its EJBs. EJB containers typically perform pooling of EJB instances to enhance performance. The EJB container also can create new EJB instances and remove existing instances.

The Methods calls :

When  a client invokes a create method in the home interface, the EJB container invokes method ejbCreate. The EJB implementation must provide an ejbCreate
method for each create method declared in the home interface.  The ejbCreate method must have the same number and types of auguments as their corresponding create methods.

The EJB container invokes method ejbRemove in response to an invocation of method remove in the home interface. The EJB container also may invoke method ejbRemove if the session expires due to lengthy inactivity. Method ejbRemove should free resources the EJB has used.

The EJB container invokes method ejbPassivate when the container determines that the EJB is no longer needed in memory. The algorithm that the EJB container uses to determine when it should passivate an EJB is application -server dependent . Many application servers enforce a least recently used policy, which  passivated EJBs that clients have not accessed recently.

When the EJB container passivates an EJB, the container serializes the state of the EJB and removes the EJB from memory. 

The EJB container invokes method ejbActivate to restore an EJB instance that the container passivated previousy. The EJB container activates an EJB instance if the client assoicated with the EJB instance invokes a business method of that EJB instance.

The EJB container reads the state information that it saved during passivation and restores the EJB instance in memory.

EJB Transaction

The Java 2 Enterprise Edition supports distributed transaction. A distributed transaction is a transaction that includes multiple databases or multiple application servers.  For example , a distributed transaction could transfer funds from an account at one bank into an account at another bank atomically.

Container Managed Transaction Type

NotSupported   Method does not support transactions . The EJB container suspends the existing transaction context if the method is invoked within a transaction context.

Required          Method requires a transaction. The EJB container creates a new transaction if the method is invoked without an existing transaction context and commits the transaction at the end of the method

Supports           Method supports transactions. The EJB container will not create a new transaction if the methods is invoked without an existing transaction context. but will execute the method as part of an existing transaction context if one is available.

RequiresNew   Method requires a new transaction. The EJB container suspends the existing transaction context and starts a new transaction if the method is invoked as part of another transaction.

Mandatory       The method must execute in an existing transaction context. The EJB container throws a TransactionRequiredException if the method is invoked without a valid transaction context.

Never               The method must not execute in a transaction context. The EJB container throws a RemoteException if the method is invoked inside a transaction context.

posted on 2008-10-07 23:09 picture talk 阅读(121) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: