com.bankframe.services.requestcontext
Interface RequestContext

All Known Implementing Classes:
SampleRequestContextFactory.SampleRequestContext

public interface RequestContext

This is a tagging interface used to identify objects that are associated with a request. These objects store some state that must be maintained across all method invocations within the request call stack.

In an application server a request corresponds to a single thread of execution We can leverage this fact to associate some information with each thread. At the start of the processing of the request we create and initialise the RequestContext object. This information then exists for the duration of the request. Note that you must exercise care when designing instances of this object.

The first point you must understand is the lifecycle of the RequestContext object. One and only one RequestContext instance will be created for each thread in the application server. This instance will be re-initialised at the start of each request.

This avoids unecessary object creation overhead by re-using the RequestContext instance for multiple requests

The second point you must understand is that since their is one instance created per thread and since the application may have hundreds or thousands of threads it is imperative that the RequestContext object does not require much memory.

For example if each RequestContext object required 20Kb of storage and the application server is serving 5000 customers, with one thread per customer then you will need 20*5000 = ~100Mb of storage. Obviously this amount of data will cause a lot of extra page faults and will significantly decrease performance and scalability.

The third point you must understand is that since the RequestContext object may be used several times in the course of a request, the methods invoked on the RequestContext object should be performant. For example a poor RequestContext implementation might use a Map or other collection type internally to store some state. This inadvisable since manipulating or interacting with Collection type objects is likely to lead to a lot of temporary objects being created. When this is being done thousands of times per second this is likely to significantly impact system performance.




Copyright © 2005, 2007, Oracle. All rights reserved.