Stateless Session Bean
by , 01-02-2012 at 05:55 PM (578 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 beanimport 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; } }









Email Blog Entry
License4J 4.0
Yesterday, 12:23 AM in Java Software