I'm currently developing a large piece of software base on JavaEE. We have followed the general guidelines of JavaEE that says that each related set of operations should go into their own EJB. We currently have over 275 different EJB classes (Stateless Session beans). This number is most likely going to grow to at least double that number.
I would like to know if the EJB containers are designed to hold that many different kinds of EJBs. I'm interested in knowing if we are going to get some bad performance penalty from having too many such classes, and if some application server level tweaking can help alleviate those hypothetical problems.
We are using Glassfish v2 with JavaEE 5 on sun's Java 6, so advice on this particular platform would be most appreciated.
For simpler web applications that can run inside less complex servlet containers like Tomcat, you wouldn't use EJB. The problem with EJBs is that they still bear all the blame they gained with early versions - most of which they honestly deserved , so nowadays they aren't so much popular.
Types of EJBs. There are three types of EJBs: session beans, entity beans, and message-driven beans.
The EJB container interacts directly with a message-driven bean—creating bean instances and passing JMS messages to those instances as necessary. The container creates bean instances at deployment time, adding and removing instances during operation based on message traffic.
EJBs should be fine-grained, so there is no problem with what you are doing if you are consistent in your design.
The EJBs are just classes, so there's nothing to worry about except for general load, which is orthogonal to the number of EJBs you have deployed.
If you are worried about performance, put in some monitoring or other performance metrics and see how things go as you add new features.
At the end of the day, would you rather maintain fewer classes with many methods, or many classes with fewer methods? I know which one I'd pick.
(Is there a way I can say "any at all" without being voted down?)
On a serious note, use as many as you need. My rule of thumb is (for both EJBs and classes in general) if you can't fully describe what the thing does in a class name of about three words, you've got it doing too much.
As far as performance goes, I suspect that if the system starts to suffer from "too many EJBs" you've got much bigger problems somewhere.
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