Stateless Session Bean (1)

Source: Internet
Author: User

1. All stateless Session Bean instances are the same.

2. for stateful ejbs, to limit the number of session beans in the memory, the EJB container must maintain the session state of the Session Bean to the hard disk or other memory, to release memory for use by other beans -- pending

(@ Prepassive ). The status of the suspended bean is returned to the memory -- activate (@ postactive ). Transient beans cannot be suspended. Use the @ prepassive and @ postactive callback methods to release and obtain resources.

3. The default value is local interface @ local. If you call EJB on the local machine (the client and the EJB container are running in the same JVM), the Local interface is used to access EJB better than the remote interface. Because remote interface access to EJB requires remote method call, and local interface access to EJB directly returns EJB reference from JVM.

4. For clients and EJB containers in the same JVM, you can use the local interface to access and remote access; for non-same JVM, you can only use remote access.

5. Some methods of session bean can be defined as local interfaces when only internal calls of the EJB container are provided without external exposure.

For example

 Package Com. Persia. EJB; Import Javax. EJB. Local; Import Javax. EJB. Remote; Import Javax. EJB. stateless; @ stateless @ remote ({operation.Class }) @ Local ({localoperation. Class }) Public   Class Operationbean Implements Operation, localoperation { Private   Int Total = 0; Private   Int Addresult = 0; Public   Int Add ( Int A, Int B) {addresult = A + B;Return Addresult ;} Public   Int Getresult (){ // Todo auto-generated method stub Total + = addresult; Return Total ;}}

 

<% Properties props = New Properties (); props. setproperty (" Java. Naming. Factory. Initial "," Org. jnp. Interfaces. namingcontextfactory "); Props. setproperty (" Java. Naming. provider. url "," Localhost: 1099 "); Props. setproperty (" Java. Naming. Factory. url. pkgs "," Org. JBoss. Naming "); Initialcontext CTX; CTX = New Initialcontext (props ); Try {Operation h = (operation) CTX. Lookup (" Operationbean/remote "); Out. println (" Call EJB through remote interface: Add: "+ H. Add (1, 1 ));} Catch (Namingexception e) {out. println (E. getmessage ());} Try {Localoperation A = (localoperation) CTX. Lookup ("Operationbean/local "); Out. println (" Call EJB through local interface: Add: "+ A. Add (1, 1); Out. println (" Call EJB through local interface: Add result: "+ A. getresult (); localoperation B = (localoperation) CTX. Lookup (" Operationbean/local "); Out. println (" Call EJB through local interface: Add: "+ B. Add (1, 1); Out. println (" Call EJB through local interface: Add result: "+ B. getresult ());} Catch (Namingexception e) {out. println (E. getmessage () ;}%>

 

If the local interface is called, it seems that initialcontext CTX = New initialcontext (); however, the props is still written here, but the local is localhost and the remote is the server address.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.