Java Reference
In-Depth Information
Because our bean is a singleton with a startup annotation, the whole process will be in-
voked during the deployment of our application. Feel free to try it out now!
Of course, the database task requires some data in the seats table or it will yield empty
results (that's not a big issue for us). If you want the application to automatically seed
some data to the database, you can create another singleton bean, for instance:
@Startup
public class DatabaseInitializer {
@PersistenceContext
private EntityManager em;
@PostConstruct
public void setup() {
SeatType seatType = new SeatType();
seatType.setPosition(SeatPosition.BALCONY);
seatType.setDescription("Test Data");
seatType.setQuantity(10);
seatType.setPrice(10);
em.persist(seatType);
Seat seat = new Seat();
seat.setSeatType(seatType);
em.persist(seat);
}
}
Be sure to add a @DependsOn("DatabaseInitializer") annotation on the
PendingSeats bean, so that the initializer runs before our database collector.
If everything goes well, you should see something like this on your console:
23:42:48,455 INFO [TaskListener] (ServerService Thread
Pool -- 54) Submitted
GenerateSeatRequestFromArtificial@4256cb0c
23:42:48,456 INFO [GenerateSeatRequestsFromDatabase]
(EE-ManagedExecutorService-default-Thread-1) Sleeping... (1)
Search WWH ::




Custom Search