• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB w.r.t performance

 
Mrutyunjay Hanchinal
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I want to know is there any special performance improvements by using Entity beans over session beans in distributed system.
Which is best to use
Session bean? Or Entity Bean? considering the performance.
Thanks in advance
Mrutyunjay
 
hanumanth reddy
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
session bean are best for performance sake
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not the whole story. It all comes down to application design. It's possible (in fact I've seen it) to write applications using Session beans and JDBC that are slower than applications that use Session beans and Entity Beans. However, the reverse can be true as well.
Entity beans (generally) are valuable from a performance standpoint because they implement a per-transaction cache. If you do a findByPrimaryKey() twice in the same transaction with the same value for the parameter, in most EJB containers you will find that this will end up only fetching the data and/or populating the bean only once. In some applications where you do a lot of back-and-forth object navigation, this becomes critical.
However, Entity beans are rotten when it comes to doing fancier things in SQL (complex joins, etc.) that straight JDBC access makes easier.
Nothing in EJB design is simple enough to put into a single email or posting to JavaRanch. I suggest you go out and buy a couple of good EJB design books like:
Richard Monson-Haefel's Enterprise JavaBeans (http://www.amazon.com/exec/obidos/ASIN/1565928695/qid=1001557526/sr=2-1/ref=sr_8_3_1/104-3236038-5363933)
Core J2EE Patterns (http://www.amazon.com/exec/obidos/ASIN/0130648841/qid%3D1001557569/ref%3Dsr%5F11%5F0%5F1/104-3236038-5363933)
or my book (below).
Kyle Brown
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
 
Mrutyunjay Hanchinal
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kyle Brown
Thanks for the reply.
In your reply it seems that you are reffering to only Container managed persistence (CMP).
If I use Bean Managed persistence (BMP) then I will be able to do all the SQL things. Does that mean BMP is better than CMP?
Ok
Please reply
Mrutyunjay
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it doesn't mean that BMP will be better than CMP, and again, it depends both on your container and how you implement your BMP beans. As I mentioned earlier -- the subject is too complex to put in a posting. Go check out the books I referred to earlier.
Kyle Brown
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing -- you can't do everything that you can do in SQL even with BMP beans -- BMP beans have a built-in limitation that will require you to perform N+1 SQL calls for each finder method unless you do some VERY sophisticated (and container-specific) programming.
See http://www7.software.ibm.com/vad.nsf/data/document2354?OpenDocument&p=1 for some of the details, at least in WebSphere.

------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!