|
Do you need help with your Java programming?
Click here for instant help with your Java code. |
Stateless Session Bean
A stateless session beans lifetime is the lifetime of a single method within it. It can contain several methods, but they are completely independent of each other. A stateless session bean cannot hold any data between calls from the client, it is designed to carry out independent operations very efficiently. Stateless session beans may scale to large numbers of clients with minimal impact to overall server resources. A stateless session bean contains of two parts. - One or more interfaces, called business interfaces, that describe what methods the stateless session bean implements. - A class that implements the business interface(s). This is the actual Enterprise Java Bean and it is recognized by it's @Stateless annotation. This is what a business interface may look like. Note that the @Local annotation is used which means that the Stateless Session Bean will be called within the same enterprise application. Had we instead declared the @Remote annotation, the Stateless Session Bean could have been called from anywhere outside the current application (through RMI). |
package com.javadb.examples; import javax.ejb.Local; /** * * @author javadb.com */ @Local public interface PasswordBeanLocal { public String getGeneratedPassword(); } |
and the implementation class (the EJB): |
package com.javadb.examples; import javax.ejb.Stateless; /** * * @author javadb.com */ @Stateless public class PasswordBeanBean implements PasswordBeanLocal { public String getGeneratedPassword() { //Code to generate password here } } |
| Do you know your Java? | |
| Take a Ten-Question-Java-Quiz! | |
Search for code examples on this site
