View RSS Feed

EJB

Stateless Session Bean

Rate this Entry
by
EJB
, 01-02-2012 at 05:55 PM (982 Views)
A stateless session (EJB Component) is an enterprise bean which gives its users a stateless service. Interface javax.ejb.SessionBean is implemented by the stateless session bean (EJB Component) and deploys to the “stateless” declarative attribute. They are known as “stateless” as conversational states are not maintained by them that are specific to the client’s session. Stateless session beans are same as the static methods or procedural applications; no instance state is present therefore to execute the method all data is provided by method arguments.

Java Code: This is the example of a stateless session bean
import java.util.Collection;
import javax.ejb.Remote;
@Remote
public interface Cart {
    public void addItem(String item);
    public void removeItem(String item);
    public Collection getItems();
}

import java.util.ArrayList;
import java.util.Collection;
import javax.annotation.PostConstruct;
import javax.ejb.Stateful;
@Stateless
public class CartBean implements Cart {
    private ArrayList items;
    @PostConstruct
    public void initialize() {
        items = new ArrayList();
    } 
    public void addItem(String item) {
        items.add(item);
    }
    public void removeItem(String item) {
        items.remove(item);
    }
    public Collection getItems() {
        return items;
    }
}

Submit "Stateless Session Bean" to Facebook Submit "Stateless Session Bean" to Digg Submit "Stateless Session Bean" to del.icio.us Submit "Stateless Session Bean" to StumbleUpon Submit "Stateless Session Bean" to Google

Updated 01-14-2012 at 06:14 PM by EJB

Categories
Session Bean , EJB Bean

Comments