开发者

SessionBean Defined methods like ejbCreate,ejbRemove implemmentation?

开发者 https://www.devze.com 2023-03-14 01:57 出处:网络
i have got bit confused about the functionality of ejbcreate and ejbremove in stateless and stateful session beans? here is my understandingand doubts:-

i have got bit confused about the functionality of ejbcreate and ejbremove in stateless and stateful session beans? here is my understanding and doubts:-

1)StatefulSessionBeans: on call to create method of home interface, subsequent call goes to ejbcreate method when we can initialize whatever we want. similarily on call to remove method of remote interface(here its remote not hemoe) subsequent call goes to ejbremove method when we can release the resource whatever we want.

Here question is does client have any control if he want to destroy some bean instance or is it taken care by container? if by container does it passivate the state before destroying the bean if in future request comes for same instance?

similarily if we want to passivate any bean, we have write code in this method to save the state of object to some file. Is that correct?

2)StatelesSessionBeans: on call to create method of home interface. call does not go to ejbcreate method of session bean.similarily call to remove method of remote in开发者_高级运维terface does not make a call to ejbremove method of session bean? If it is true when does the container give call to ejbcreate and ejbremove method in case of StatelesSessionBeans?


1) StatefulSessionBeans

Here question is does client have any control if he want to destroy some bean instance or is it taken care by container?

Both. In EJB 3.0+, you can annotate a method with @Remove to indicate that you want the bean to be removed after the method completes. Prior to EJB 3.1, you would use the EJBObject.remove or EJBLocalObject.remove methods. If you don't explicitly remove it, the container will automatically clean up the bean after a timeout. In EJB 3.1, you can control the duration with the @StatefulTimeout annotation.

if by container does it passivate the state before destroying the bean if in future request comes for same instance?

Containers will passivate the bean when they're no longer needed based on vendor-specific policies. For example, if there are too many active SFSBs, the container might passivate the least-recently-used bean. So long as the bean is used again before it times out, the container will automatically. recreate/activate the bean.

similarily if we want to passivate any bean, we have write code in this method to save the state of object to some file. Is that correct?

No, the container will automatically persist the values of all non-transient fields in the bean, even if the bean is not marked Serializable, but you can implement Serializable if you want more control.

2)StatelesSessionBeans

on call to create method of home interface. call does not go to ejbcreate method of session bean.

Correct, create for a stateless bean will simply return a wrapper/proxy. As soon as you call a method, the container will allocate a bean (usually from a pool), invoke the method, and then deallocate the bean (usually return to the pool).

similarily call to remove method of remote interface does not make a call to ejbremove method of session bean?

Correct, the remove method has no effect on a stateless bean. The container manages the pooled bean instances.

If it is true when does the container give call to ejbcreate and ejbremove method in case of StatelesSessionBeans?

The container is free to do either when it wants. Usually, the container will create a new bean when there is not one available in the pool and the pool has not reached its hard maximum size. Usually, the container will remove an instance only if it has created too many, or if there are too many beans in the server and a bean has not been used for awhile.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号