Caching in Service Locator implementations

Here you can find an article by Bobby Woolf that describes why caching inside a Service Locator in J2EE 1.3 applications may have unexpected behavior.

The article also provides a nice explanation of the EJB resource reference mechanism.

Update (19/9/2005):

BTW this is why the Adventure Builder (the sample application developed by SUN for J2EE 1.4) has two implementations for the Service Locator design pattern.

The first implementation is for the EJB tier and does not have caching to avoid the problem explained in the article.

The second implementation is for the web tier and uses caching since resource references in the web tier are the per web application and it is safe to cache them in a static variable.