Enterprise JavaBeans are server-side, moduler, and reusable components that comprise specific units of functionality. They are similar to the classes we create every day, but are subject to special restrictions and must provide specific interfaces for container and client use and access. In addition, they can only run properly in an EJB container, which manages and invokes specific life cycle behavior. You should consider using EJB components when the application design requires scalability, transactional processing, or availability to multiple client types.
EJB components come in three varieties, each with its own defined role and life cycle:
1. Session beans: These may be either stateful or stateless, and are primarily used to encapsulate business logic, carry out tasks on behalf of a client, and act as controllers or managers for other beans.
2. Entity beans: Entity beans represents persistent objects or business concepts that exist beyond a specific application’s lifetime; they are typically stored in a relational database. Entity beans can be developed using bean-managed persistence, which is implemented by the developer, or container-managed persistence, implemented by the container.
3. Message- driven beans: Message-driven beans listen asynchronously for Java Message Service(JMS) messages from any client or component and are used for loosely coupled, typically batch-type, processing.
EJB Programming Restrictions
1. An enterprise Bean must not use read/write static fields. Using read-only static fields is allowed. Therefore, it is recommended that all static fields in the enterprise bean class be declared as final.
2. An enterprise Bean must not use thread sychronization primitives to synchronize execution of multiple instances.
3. An enterprise Bean must not use the AWT functionality to attempt to output information to a display, or to input information from a keyboard.
4. An enterprise Bean must not use the java.io package to attempt to access files and directories in the file system.
5. An enterprise bean must not use attempt to listen on a socket, accept connections on a socket, or use a socket for multicast.
6. The enterprise bean must not attempt to query a class to obtain information about the declared members that are not otherwise accessible to the enterprise bean because of the security rules of the java language. The enterprise bean must nto attempt to use the Reflection API to access information that the security rules of the java programming language make unavailable.
7. The enterprise bean must not attempt to create a class loader; obtain the current class loader; set the context class loader; set security manager; create a new security manager; stop the JVM; or change the input, output and error steams.
8. The enterprise bean must not attempt to set the socket factory used by ServerSocket, Socket, or the stream handler factory used by URL.
9. The enterprise bean must not attempt to manage threads. The enterprise bean must not attempt to start, stop, suspend, or resume a thread; or to change a thread’s priority or name. The enterprise bean must not attempt to manage thread groups.
10. The enterprise bean must not attempt to directly read or write a file descriptor.
11. The enterprise bean must not attempt to obtain the security policy information for a particular code source.
12. The enterprise bean must not attempt to load a native library.
13. The enterprise bean must not attempt to gain access to packages and classes that the usual rules of the Java programming language maje unavailable to the enterprise bean.
14. The enterprise bean must not attempt to define a class in a package.
15. The enterprise bean must not attempt to access or modify the security configuration objects(Policy, Security, Provider, Signer, and Identity).
16. The enterprise bean must not attempt to use the subclass and object substition features of the Java serialization protocol.
17. The enterprise bean must not attempt to pass this as an argument or method result. The enterprise bean must pass the result of SessionContext.getEJBObject(), SessionContext.getEJBLocalObject(), EntityContext.getEJBObject(), or EntityContext.getEJBLocalObject() instead,