The Enhydra class provides static methods that allow each application
to conviently get at their application object. It also provides
access
This class implements dynamically scoped global variables, accessed
via static methods. Which variable is accessed (and thus which
Application object is returned) depends on the flow of control of
the program before the access (the call stack).
Currently a hashtable keyed on the threads themselves is used to
store the different Application, in Java 1.2 threads will have a field
already available for storing client data.
Normal usage of this class is to call register() when
a thread enters your application, then unRegister()
when it leaves. It is very important that every register()
is matched with an unRegister() , or else it will be
a memory leak, threads that re-enter the application will have
a stale Application (until the first register() ), and
an extra pointer to the Application will be left around, preventing
garbage collection.
If no thread is passed in (the normal usage), the current thread is
used. If your application creates new threads, these will not initially be
associated with any Application. These new threads can be passed in to
register() , to assocaiate them with an Application.
You may call register() before calling start()
on the thread.
To ensure that every register() is balanced with an
unRegister() , the following code is recommended:
Enhydra.register(application);
try {
doSomeWork();
} finally {
Enhydra.unRegister();
}
This will ensure that the unRegister() is called even if
an exception is thrown, but it will not interfere with the exception
processing.
version: $Revision: 1.3 $ author: Paul Morgan author: Andy John since: LBS1.8 |