Constraints on Beans

April 22, 2008 at 3:08 am (EJB, Unit 3)

Common Constraints for all beans:

  • EJB cannot start new threads or use thread synchronization primitives.
    • Container is responsible for creating and managing new bean instances
    • EJB beans are not allowed to spawn threads themselves, but the container can run multiple beans concurrently.
    • This prevention is needed not to interfere the container’s management of its beans
  • EJB cannot directly access the underlying transaction manager
    • Because the container has the responsibility for managing transactions.
    • If bean declares its transaction management as TX_BEAN_MANAGED, is allowed to use a javax.jts.UserTransaction to manage the state of its own transaction.
  • The bean cannot use the JDBC commit and rollback primitives.
    • This constraints exists because the container is responsible for issuing the commit and rollback instructions for transaction-enabled beans.
    • A bean with a transaction attribute of TX_NOT_SUPPORTED, however, can use JDBC commit or rollback, because no external transaction manager exists.
  • Beans are not allowed to change their java.security.Identity at runtime.
    • The identity is typically set up at deployment time by the system administrator
    • Runtime changes are disallowed to prevent malicious beans from acquiring unintended privileges.
  • EJB cannot have read/write static variables. But “static final” variables are allowed.

Post a Comment

You must be logged in to post a comment.