Java Reference
In-Depth Information
@Singleton
@Startup
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class TheatreBox {
. . . .
public void buyTicket(Seat seat) {
synchronized (this){
seat.setBooked(true);
}
}
Since concurrent access is restricted when a thread enters the synchronized block,
no other methods are then allowed to access the object while the current thread is in
the block.
Cooking session beans
Our singleton EJB is equipped with the methods for handling our cache of theatre
seats. We will now add a couple of session beans to our project for managing the
business logic: a stateless session bean that will provide a view of the theatre seats
and a stateful bean that will behave as a payment gateway to our system.
Note
The choice of splitting our information system into two different beans is not part
of a design pattern in particular, but serves a different purpose. That is, we would
like to show how to look up both types of beans from a remote client.
Adding a stateless bean
So, the first bean we will create is
com.packtpub.as7development.chapter3.ejb TheatreInfoBean that
barely contains the logic for looking up the list of theatre seats. In practice, this acts
as a façade for our singleton bean.
Search WWH ::




Custom Search