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!

Bookmark and Share




Need help with your Java code? It's secure and confidential.
This is how it works:
Send a detailed description of what you need help with, the more details the better. Also provide a deadline for when it has to be finished. More time means better chance of putting your request into the schedule.

If the request is serious you will shortly receive an email with the price, to which you have to respond if you accept.

Once you have accepted, the work will begin on developing your code by an experienced Java developer. When the code is finished a link to a secure payment will be sent to you.

The source code is then sent to you once the payment is completed.

IMPORTANT! The request needs to be very detailed, else it may be ignored.


Write your detailed request here:

E-mail address: