View RSS Feed

My Java Tips

Using @Stateless

Rate this Entry
by , 11-03-2011 at 07:25 PM (853 Views)
Stateless session beans are those, who do not keep track of the information that is passed from one method call to another. Thus, they donít have internal state and each invocation of a stateless business method is independent of its previous invocation. These beans are simple to manage for the container. For example: tax calculation is a business task and we can have a bean for that. It will simply calculate the tax for an employee. It can be a stateless session bean since each time we call it, we need it to calculate tax of a different employee which has nothing to do with the previous results.


An example is presented below:

Java Code:
import javax.ejb.Stateless.*;

@Stateless(name="CalculateEJB")
public class CalculateEJBBean
implements CalculateEJB
{
int value = 0;
public String incrementValue()
{
value++;
return "value incremented by 1";
}
}

Submit "Using @Stateless" to Facebook Submit "Using @Stateless" to Digg Submit "Using @Stateless" to del.icio.us Submit "Using @Stateless" to StumbleUpon Submit "Using @Stateless" to Google

Tags: None Add / Edit Tags
Categories
EJB , Java EE

Comments