Home > Articles > Programming > Java

  • Print
  • + Share This
This chapter is from the book

1.6 EJB products

To construct EJB applications, you will need an EJB server, or something that includes an EJB server. This section discusses the features you can expect an EJB server to have—in addition to support for the EJB Specification, of course—and lists some products that are currently available.

1.6.1 Features of EJB products

The EJB architecture was developed to support large, critical (high reliability), distributed applications. It is the responsibility of the EJB server vendor to provide a product that allows this goal to be met. The EJB Specification has little to say about the ways in which it will do this. In practice, containers normally use some or all of the following strategies.

Load sharing

In many large systems, a single server—however powerful—will not be able to support the total load of the application. In any case, one large system is less effective than two smaller ones at handling failures. In practice, therefore, all commercial EJB products are able to distribute load between servers.


Strictly speaking, to claim J2EE compliance for a product, a vendor must be able to produce the results of standard J2EE compliance tests. Not all vendors do so, but this does not necessarily mean the product is noncompliant or inadequate. Moreover, even demonstrable compliance says little about the product's support for load balancing, fault tolerance, or other features likely to be important in an enterprise application. What is worse, some of the compatibility tests are not very demanding and are easy to pass. This allows some vendors to claim compliance and yet have a product that is weak in certain areas. In short, don't assume that all EJB products that carry the stamp 'J2EE compliant' are equivalent. Determine the features that are important to your projects, and ask vendors what support is provided for each feature.

As a client's first access to an EJB service is via a name-service lookup, coarse-grained load sharing can be implemented at the point in which the EJB's factory object is looked up (more about factory objects later). Each successive request for the same EJB factory can be directed to a different server, with the EJB itself distributed on all the servers. This process can be governed by the name lookup service (on the server), or by the client. In the latter case, typically the work will be done in a proxy on the client, so that the developer does not have to code the client differently.

Such a strategy is straightforward to implement and can work reasonably well where the number of clients is large and the load imposed by each client relatively small. With a small number of demanding clients, load can easily get out of balance, as there is no opportunity for rebalancing once the factory object has been located.

Alternatively, we can balance at the method call level, if EJBs are pooled or the instance variables of unpooled EJBs can be synchronized across servers. This allows more rapid adaptation to changes in load, but is complex to implement.

In practice, load sharing is much more complicated than it first appears. The reason is that some EJB components—notably stateful session EJBs—have state that is meaningful to a client. This means that requests from the client cannot be distributed arbitrarily. Instead, they must either be bound to the server on which that client's state is stored, or we must provide a method for synchronizing the state across servers. This issue will be discussed in more detail later, when we look at failover strategies.

Needless to say, the method of load balancing will depend on the server vendor but, if you follow the rules set out in the EJB Specification and the guidance given in this book, this should not present a problem.

Resource pooling

The most common form of resource pooling is database connection pooling, which is supported by all commercial EJB products. This topic is discussed in detail in Chapter 8. The purpose of resource pooling is to allow large numbers of Java objects to have access to a small number of instances of a shared resource. In the case of database connections, these are computationally expensive to open and resource-hungry to maintain. A connection pooling scheme allows the mapping of a large number of 'virtual' connections onto a much smaller number of real connections to the database. The J2EE scheme defines a method for access to shared resources that abstracts away from the underlying resource management system. This means that, to a large extent, the Java code required to interact with the resource is the same as it would be without the application server. However, resource pooling schemes work best if the code does not hinder their operation, so an understanding of their operation is advantageous.

Failover and redundancy

In critical applications, we need to be sure that if a single server fails, the application itself can continue to operate, albeit at reduced performance. Any load sharing system will allow a degree of fault tolerance; it is the ability to handle a failure with no loss of service that distinguishes such a scheme from true 'failover.' In order to achieve a failover with no loss of service, clients must continue to be able to interact with the EJB application without interruption. This is straightforward for EJBs that have no client state, but where state is involved there is more to it. We have already seen that we could avoid the problem of state in load sharing simply by binding incoming client requests to the server that is carrying the client's state. For failover, this simply won't do: We must find a way to synchronize the state.

The problem is that, unlike servlets (page 549), EJBs do not keep their state in nice, neat packets. The state of an EJB is in its instance variables, and the instance variables of its instance variables, and so on. Synchronizing these efficiently is a far from straightforward job. Happily, it's a job for the server vendor, not for the application developer.

A number of EJB products are now able to offer failover support for stateful session beans. Typically, the EJB instance that is most up-to-date has to be serialized, and the serialized version recreated on each participating server. For maximum reliability, this needs to happen after every method call that changes an instance variable. Clearly, this could be very ine3cient if used carelessly.

1.6.2 Integration

Many enterprise-scale EJB products also offer impressive support for other distributed component technologies, notably CORBA. In addition, an EJB product is likely to be a part of a larger application server that includes some or all of the following:

  • support for other J2EE components, such as servlets and JSPs;

  • a distributed transaction manager;

  • a relational database;

  • a directory server;

  • a messaging service.

In addition, many products provide vendor-specific extensions that allow EJBs to integrate with popular back-end systems like SAP R/3. The problem with vendor-specific extensions is, of course, that the EJBs that use them are not portable across servers. JCA is starting to alleviate this problem, by providing a cross-platform technique for interfacing with arbitrary data sources.

1.6.3 Platform support

If an EJB server is written entirely in Java (a few are), then it may be possible to produce a truly platform-independent product. In reality, this is unusual. Most products either include native machine code components or communicate with other services that are themselves platform-specific. In practice, vendors typically support a small number of platforms, often limited to Sun Solaris on Sparc platforms, and Microsoft Windows NT on Intel-based PCs. Only a few vendors (notably IBM) support an impressively large range of platforms. At the time of writing, support for Microsoft Windows 2000 and Linux, for example, was scant.

1.6.4 Vendors and products

There are a number of products on the market that support EJB applications, as well as a number of open source EJB servers. However, there are relatively few dedicated EJB servers commercially available. Normally, one has to buy a product that supports EJBs as part of a wider set of functionality. Commercial products that support EJBs tend to fall into two groups.

  • Database engines with EJB support. Many vendors with strong reputations in the relational database field are producing EJB products that integrate with their databases. Typical examples are Oracle's 8i and 9i and, to a certain extent, IBM's WebSphere.

  • Well-established application servers whose vendors have embraced the J2EE model and adapted their products to support EJB. Examples include the SunONE Application Server4from Sun Microsystems, and products from Pra-mati and Gemstone.

Another group, which is currently small but likely to expand, is products from vendors of development tools and IDEs (e.g., Borland's Inprise).

Knowing a product's background gives some clue to the areas in which it is likely to excel. For example, a product from a database vendor should be able to offer a high degree of optimization of database performance. A product from an IDE vendor should o3er ease of development. Of course, all products, regardless of heritage, should support the functionality required by the EJB Specification.

Table 1.1 lists some of the products available that include support for EJB 1.1 or later. This list was probably not exhaustive at the time it was written, and it certainly won't be exhaustive by the time you read it.

When considering the price of an EJB product, bear in mind that a product that supports the full range of J2EE services (servlets, JSP, etc.) is almost certainly going to be more expensive that a dedicated EJB server. If it includes a database and a distributed transaction manager as well, then it is likely to be very expensive indeed.

  • + Share This
  • 🔖 Save To Your Account