Book Image

EJB 3 Developer Guide

By : Michael Sikora
Book Image

EJB 3 Developer Guide

By: Michael Sikora

Overview of this book

Table of Contents (18 chapters)
EJB 3 Developer Guide
Credits
About the Author
About the Reviewers
Preface
Annotations and Their Corresponding Packages

Timer Service Examples


In the context of banking applications, we might use timers for housekeeping activities such as deleting temporary files, reporting on customers with no accounts, accounts with no corresponding customers, or unusual account activity. However, in order to provide the reader with examples that he or she can run themselves we will provide examples, which while not very realistic, do demonstrate the use of the timer service.

A Single Event Example

Suppose in our banking scenario we want to give all savings accounts a $10 bonus after a period of time. We first modify the stateless session BankServiceBean.createAccounts() method to create a timer as soon as we have created the accounts.

@Stateless
public class BankServiceBean implements BankService {
@Resource
private TimerService ts;
public void createAccounts() {
a1 = new Account();
a1.setId(1);
a1.setBalance(99);
a1.setAccountType("C");
em.persist(a1);
a2 = new Account();
a2.setId(2);
a2.setBalance(520);
a2.setAccountType...