Enterprise JavaBean Restrictions

The EJB container provides functionality such as life cycle management, threading, security, and resource pooling. Enterprise bean instances may be distributed; that is, they may run in separate JVMs or on separate machines. To efficiently manage resources such as memory, the container can swap the instances from memory to disk.

To run properly, the container imposes certain restrictions on the components that live within. This ensures the proper functioning of the container and the Enterprise JavaBean's portability and scalability.

The following are some of the restrictions imposed on Enterprise JavaBeans:

  • Must not read/write static fields: It's okay to use read-only static fields. It is better to declare the static fields as final. Static fields are shared among all instances of a particular class. Updating a static field works if all the instances are running in the same JVM, but it doesn't work if the instances are distributed in separate JVMs.

  • Must not use thread synchronization primitives to synchronize execution of multiple instances: Thread synchronization works if all the instances are running in the same JVM, but doesn't work if the instances are distributed in separate JVMs.

  • Must not create or manage (start, stop, suspend, resume, change priority) threads: The EJB container is responsible for creating and managing threads. Allowing the Enterprise JavaBean instances to create and manage threads interferes with the container functionality.

  • Must not read or write files and directories or access file descriptors: Files, directories, and file descriptors are typically local resources to a machine, and can't be distributed across machines in a portable way. Also, access to the file system is a security hazard because the Enterprise JavaBean could potentially read and write the contents of sensitive files.

  • Must not listen or accept connections on a socket: This isn't allowed because if an Enterprise JavaBean is listening on a socket, it can't be swapped to disk. It's okay for Enterprise JavaBeans to be network socket clients.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.24.106