The TaxCalculator queries the database for all Employee entity bean objects and calculates the payroll tax for each employee. Assume that the TaxCalculator session bean needs to perform several database queries and some highly CPU-intensive calculations to determine the payroll tax for an employee. If the TaxCalculator session bean must calculate the payroll tax for each employee sequentially, calculating the taxes for several thousand employees would take a lot of time. Improving the performance of the TaxCalculator session bean would be easy if it could create threads that would calculate the employee payroll taxes concurrently. This is just one example of the kind of problem that can be solved by introducing asynchronous enterprise bean components into an application.
Similar problems are common in the development of large-scale enterprise applications.
To create efficient EJB applications such as the payroll example, however, we must be able to support asynchronous processing. We have three choices. First, client-side multithreading moves the multithreaded code from the server to the client. Second, callbacks get around multithreaded enterprise beans by notifying clients of events they are interested in. Let's examine these methods a little bit closer.