The Difference between EJB and CDI-managed beans

Classes are annotated with @Stateless, @Stateful, or @Singleton to make them EJBs. These beans are managed by the container or application server and already implements a number of cross-cutting concerns, such as transactions, monitoring, pooling, and more. Stateless beans doesn't maintain the state interaction between the client and the server. The instances of the beans that are annotated with @Stateless are actually pooled. There will be several instances of these beans. The server manages them and we can configure this if we want to. If we access an instance of these beans, we get an instance that might have been created previously from the pool. After using it, it is returned to the pool. Stateful beans maintain the interaction between the client and the server.The instances of the beans that are annotated with  @Stateful are not pooled. These beans are created for a particular user's session and remain associated with that session till the session is active. For Singleton beans, only one instance is maintained in the application.

CDI-managed beans are typically POJOs that are injected. These beans don't come with any cross-cutting concerns, such as transaction, monitoring, and pooling. If we need these, we can add annotations to the CDI-managed beans, such as @Transactional.

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

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