• Post Reply Bookmark Topic Watch Topic
  • New Topic

Coarse grained beans  RSS feed

 
Mahendra Nambiar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone explain what the benefits are of coarse grained versus thin-grained EJBS and how this affects clients?
thanks,
Mahendra
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A coarse-grained view of data avoids remote calls to the ejb container, suppose you have a customer ejb, if any time you need some information from him you�re gonna make a remote call , this hurts performance and can generate lots of networking trafic, so its better you have some kind of facade for the entity and pass all the object(or a collection of such) in one call with all the attributes already set, if your object is not an ejb you should make it Serializable.
Take a look at: http://java.sun.com/j2ee/blueprints/design_patterns/index.html
You problably gonna have much fun.
 
Matjaz Juric
Author
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Coarse grained interfaces minimize the communication overhead of remote method invocations. Therefore instead of setting or getting attributes one by one it is more efficient to do this with one remote method invocation. Often coarse grained interfaces are combined with Value Objects, which gather the attributes and possibly some validation logic.
Cheers,
Matjaz

------------------
Matjaz Juric
Author of Professional EJB
 
faisal mahmood
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think communication overhead is dependant on the utilization of the data represented by the EJB
Let's assume you need to use all the attributes of a bean which is going to be serialized using RMI. If it is a fine-grained bean then you will only need to do network transfer only once (and use all the get methods). If it was going to be coarse-grained bean then you will need to do more than one network transfer. So, this would mean a communication overhead for coarse-grained bean.
From my point, fine-grained bean is better if you don't need to utilize the bean attributes fully. Otherwise coarse-grained is preferred.
Correct me if I am wrong.
Faisal
SCJP2,SCWCD,SCJEA(p1),Websphere,OOAD using UML
 
Matjaz Juric
Author
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's assume we have 10 different attributes. A fine grained interface would expose 10 getter/setter methods. To set the values of all ten attributes we would need 10 remote method invocations.
In a coarse grained interface we would use a single method that would take 10 parameters.
The fact is that one remote method invocation with 10 parameters will execute faster than 10 remote invocations. Each remote invocation namely has a certain overhead (around 1 ms in a typical configuration on a 100MBps network).
However there is not obstacle to combine both approaches and to design beans with both, fine and coarse grained methods.
Cheers,
Matjaz

------------------
Matjaz Juric
Author of Professional EJB
 
Ramesh Talwar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
How about passing/returning Vector objects instead of 10 parameters.
Will overhead reduce on passing Vector objects ???
Ramesh.
 
Mahendra Nambiar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou very much for help
=Mahendra
 
Matjaz Juric
Author
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to our performance measurements the marshaling overhead is lower for simple data types. However in real world examples you will in most cases consider defining value objects. This will add a little overhead but will still result in faster performance than fine grained interfaces.
To learn more about EJB performance please join the tutorial No. 67 on OOPSLA�2001 conference.
Cheers,
Matjaz

------------------
Matjaz Juric
Author of Professional EJB
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!