Avijeet Dash and Satyabrata Dash
While using the J2EE Framework one should be aware of the consequences of
using it under various scenarios. The most critical concern in a distributed
paradigm is the latency time, that is the time taken to serve a client request.
And this time is significantly higher compared to a local computing environment,
as the object communication is potentially remote. One such consideration is the
use of Entity beans. We learnt to use Entity beans as a coarse grained object in
the Composite Entity pattern. Composite entity reduces the number of
fine-grained entity beans and thus inter-entity bean communications, which have
a significant overhead. One more consideration while using Entity beans is the
use of its finder methods. Ejb-finder methods are used in a search and query
context, where the client wants a list of items and the size is unknown, which
could be very large.
The way ejb-finder methods work is they return a collection of EJBObject
references. Every container implementation has a certain amount of finder method
overhead for creating a collection of EJBObject references. Finder method
behavior performance varies depending on a vendor's container implementation.
According to the EJB specification, a container may invoke ejbActivate() methods
on entities found by a finder method. At a minimum, a finder method returns the
primary keys of the matching entities, which the container returns to the client
as a collection of EJBObject references. This behavior applies for all container
implementations. Some container implementations may introduce additional finder
method overhead by associating the entity bean instances to these EJBObject
instances to give the client access to those entity beans. This overhead can
significantly impede application performance if the application includes queries
that produce many matching results.
Value List Handler Pattern suggests an alternate approach of using ejb-finder
methods, that is to use DAO objects to query using JDBC and store results in a
list object holding fine-grained value objects. There are many advantages of
this approach.
- Avoiding overheads associated with ejb-finder methods . When the client
- Caching of searched results, typically when client needs huge list of
items for browsing, it may be less concerned about its correctness, what the
client needs is a fast access of the list in a page-by-page iterator manner
where each page displays a sub-list of the result set. When the value list
handler is implemented in the state-full session bean fashion the list can be
saved for further client requests. A read-only data pattern can be used load
data at start up time to avoid database lookups for static kind of data. - Querying flexibility, using ejb-finders in CMP the query has to be
specified in the EJB Query language in the configuration xml. This language
has lesser flexibility that using sql in DAO objects, though EJB2.0 EJBQL has
more flexibility. - Allows differing entity bean transaction. While client views large
list of data transaction requirements are not required. And the transaction
requirements can be differed until one item has been selected for updation.
While updating or inserting single row data entity bean offers better option. - Improves network performance. Network performance may improve because
only requested data, rather than all data is shipped (serialized) to the
client on an as-needed basis.
is the presentation tier, and a large list of items is required for view
operations, its efficient to pass collection of fine-grained local value
objects rather than remote entity beans collection. When the client is the
business tier and the list of items resulted could be less, using finder
method could be preferred.
Structure
of Value List Handler
Sequence
diagram of Value List Handler
Sample Code
/*
This sample code of value list handler is found at
http://www.phptr.com/corej2eepatterns/codeChap8_2.html#ex8.29
http://www.phptr.com/corej2eepatterns/codeChap8_2.html#ex8.30
http://www.phptr.com/corej2eepatterns/codeChap8_2.html#ex8.31
*/
Reference
http://developer.java.sun.com/developer/restricted/patterns/ValueListHandler.html
http://www.precisejava.com/javaperf/j2ee/Patterns.htm
http://www.orionserver.com/docs/jdbc/javax/sql/CachedRowSet.html
http://java.sun.com/blueprints/patterns/j2ee_patterns/fast_lane_reader/index.html
The authors are senior developers at MindTree Consulting. They can be reached
at avijeetd@mindtree.com and satyabrata_dash@mindtree.com.