Java Reference
In-Depth Information
Table 1.1. EJB services
Service
What it means for you
Registry, dependency injec-
tion, and lookup
Helps locate and glue together components, ideally through simple configuration. Lets
you change component wiring for testing.
Lets you take appropriate actions when the lifecycle of a component changes, such as
when it's created and when it's destroyed.
Lifecycle management
EJB makes all components thread-safe and highly performant in ways that are completely
invisible to you. This means that you can write your multithreaded server components as
if you were developing a single-threaded desktop application. It doesn't matter how com-
plex the component is; EJB will make sure it's thread-safe.
Thread safety
EJB automatically makes all of your components transactional, which means you don't
have to write any transaction code while using databases or messaging servers via JDBC,
JPA, or Java Message Service (JMS).
Transactions
EJB creates a pool of component instances that are shared by clients. At any point in
time, each pooled instance can only be used by a single client. As soon as an instance is
done servicing a client, it's returned to the pool for reuse instead of being frivolously dis-
carded for the garbage collector to reclaim.
You can also specify the size of the pool so that when the pool is full, any additional re-
quests are automatically queued. This means that your system will never become unre-
sponsive trying to handle a sudden burst of requests.
Similar to instance pooling, EJB also automatically pools threads across the container for
better performance.
Pooling
The EJB container manages the state transparently for stateful components instead of
having you write verbose and error-prone code for state management. This means that
you can maintain the state in instance variables as if you were developing a desktop ap-
plication. EJB takes care of all the details of session/state maintenance behind the scenes.
State management
EJB steps in to optimize memory by saving less frequently used stateful components into
the hard disk to free up memory. This is called passivation . When memory becomes
available again and a passivated component is needed, EJB puts the component back into
memory. This is called activation .
Memory management
EJB 3 allows you to write message processing components without having to deal with a
lot of the mechanical details of the JMS API.
Messaging
Security
EJB allows you to easily secure your components through simple configuration.
EJB lets you schedule any EJB method to be invoked automatically based on simple re-
peating timers or cron expressions.
Scheduling
Asynchronous processing
You can configure any EJB method to be invoked asynchronously if needed.
EJB 3 introduces AOP (aspect-oriented programming) in a lightweight, intuitive way us-
ing interceptors . This allows you to easily separate out crosscutting concerns such as log-
ging and auditing, and to do so in a configurable way.
Interceptors
EJB 3 can transparently turn business components into Simple Object Access Protocol
(SOAP) or Representational State Transfer (REST) web services with minimal or no code
changes.
Web services
In EJB 3, you can make components remotely accessible without writing any code. In ad-
dition, EJB 3 enables client code to access remote components as if they were local com-
ponents using dependency injection (DI).
Remoting
You can easily unit- and integration-test any EJB component using embedded containers
with frameworks like JUnit.
Testing
 
Search WWH ::




Custom Search