Java Reference
In-Depth Information
connection.close();
connection = null;
...
}
3.2.7. Using stateless session beans effectively
Like all technologies, EJB and stateless session beans have best practices to follow and
anti-patterns to avoid. In this section we'll mention some of these points.
Tune pooling
As we discussed in section 3.2.2 , tuning pooling correctly is a critical part of getting the
most out of stateless session beans. Generally, the defaults of most application servers are
good enough, but tuning can truly optimize your application and prime it for performance
under pressure. The importance of taking advantage of the EJB monitoring features built
into most application servers also can't be understated. Making use of monitoring will truly
help you understand the runtime patterns of your application.
Don't abuse remoting
Recall that the default interface type is local. While remote interfaces are very useful when
they're needed, they can be a serious performance killer if used otherwise. The issue is that
if you accidentally use the @Remote annotation instead of the @Local annotation, you'll
still be able to transparently inject the remote EJB using @EJB as though it were a local
EJB without realizing it. This is why it's very important that you avoid the @Remote an-
notation unless it's really needed.
Use interfaces
Although it's technically possible to avoid using interfaces with EJB 3.1, we recommend
that you use interfaces anyway unless you're developing a prototype or using session beans
as JSF-backing beans. If you're developing a service, it's best to maintain loose coupling
through an interface for easier testability as well as future flexibility.
Search WWH ::




Custom Search