Java Reference
In-Depth Information
Adding a stateful bean
In order to keep track of how much money our customer has got in his pocket, we will need
a session-aware component. Turning a Java class into a stateful session bean is just a matter
of adding a @Stateful annotation on top of it, as in our example
class. This is shown in the following code:
@AccessTimeout(value = 5, unit = TimeUnit.MINUTES)
public class TheatreBooker implements TheatreBookerRemote {
private static final Logger logger =
private TheatreBox theatreBox;
private int money;
public void createCustomer() { = 100;
public int getAccountBalance() {
return money;
public String bookSeat(int seatId) throws
SeatBookedException, NotEnoughMoneyException,
NoSuchSeatException {
final int seatPrice =
if (seatPrice > money) {
throw new NotEnoughMoneyException("You don't
have enough money to buy this " + seatId + " seat!");
Search WWH ::

Custom Search