Why should I ever use EJB? What can I get from it that I can't get in other ways?
What are the advantages of using EJB compared to POJO?
EJBs are managed and monitored by the Java EE application server, it takes care of creating and providing them to the clients via dependency injection and managing their lifecycles. EJBs are kept by the app-server in pools. Each time a client acquires an EJB, the app-server picks one from the pool and assign it to the client. After the client is done with it (there is no reference to it left on the client side) it is returned to the pool and is ready for assigning to other clients.
Pooling is very significant for scalability of the application. You do not have to change anything to a deployed application to handle growing load and your application will not take the app-server on the knees if gets too high load since the amount of resources is limited. Everything is done by configuring the app server.
EJBs can - if accordingly annotated - handle transactions and asynchronous execution and can be exposed to remote clients.
There are four types of EJBs:
Session beans
Message driven beans
While EBJs offer all that and may other things, POJOs are just POJOs nothing less and nothing more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With