Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

3.10 EJB rules, standards and limitations

The EJB Specification sets out many rules about how an EJB’s implementation class and its interfaces should be coded. These can be divided into the following general groups.

Common sense For example, methods on a remote interface should be public (nothing would work properly otherwise), and EJBs should not attempt to use graphics operations to produce output (who would see it?).

Not obvious, but clearly necessary when understood For example, an EJB should not use writable static instance variables. This is because the EJB server may pool instances of the EJB’s classes in different JVMs. It would be awkward to keep the static instance variables synchronized between different JVMs.

Required to help container developers meet the EJB Specification The rules about thread management are in this category. EJBs are not allowed to manipulate threads, because this would make it almost impossible for the EJB container to maintain a single-thread model for EJBs.

Contested Some restrictions on EJBs are contested by many EJB developers and container vendors. For example, EJBs are prohibited from reading or writing files through the local filesystem. The EJB Specification merely says that file operations are “not well suited” to business data processing. Others have argued that it should be up to the EJB developer to decide what programming techniques are suited to the application.

There is not enough space in this book to list and describe all the rules and standards that EJB developers should follow (that, after all, is what a 500-page specification is for), and in any event, many of them are unlikely to be relevant in practice (e.g., EJB methods should not be final). The more important issues are discussed in Chapter 14.

  • + Share This
  • 🔖 Save To Your Account