Yesterday I spent most of the day helping Worldwide Support to diagnose a sporadic problem that a customer was facing in their BC4J/Struts application. The problem only reproduced on one machine, and when JDeveloper was run in the debugger to study the problem further it refused to reproduce. The kinds of errors that the customer was reporting were sporadic errors like:
- "Component object TheirViewObjectName has no parent"
- NullPointerException calling findByKey()
This customer was not leveraging the built-in support that BC4J provides for Struts applications to acquire and release the AM instance for you from the pool, and instead was using a home-brew approach to acquire and release the AM needed during the span of each single HTTP request. The problem boiled down to the fact that they were caching the ApplicationModule instance in a private member variable of their Struts Action and this was encountering thread-safety issues. The Struts JavaDoc for the Action class says:
Actions must be programmed in a thread-safe manner, because the controller will share the same instance for multiple simultaneous requests. ... Instance and static variables MUST NOT be used to store information related to the state of a particular request.
when what you save in that private variable is an ADF Business Components application module, funny things can happen when different threads are "peeking" and "poking" at that same private member variable. For example, one thread might free the application module that another thread is just about to use for a findByKey().
I rewrote their code to save the AppModule instance as an HttpServletRequest attribute, and access it from there during the request to avoid these threading issues. This made the sporadic issues go away.
Forewarned is forearmed! :-)
11:21:54 AM
|