fc.util
Class ThreadLocalObject
java.lang.Object
fc.util.ThreadLocalObject
public final class ThreadLocalObject
- extends java.lang.Object
Useful to store thread-local instances of any object. This class is intended
for servlets/molly pages. Instead of static get/set methods, this class
must be instantiated and the instance methods used to get/set the objom
object. This allows multiple instances of this class in the webapp, with
each instance being able to get/set a separate object.
Each thread must remember to individually create a separate
object instance and store it via the set method. The usage idiom
is:
//WebApp has a map of ThreadLocalObjects
ThreadLocalObject tl_obj = WebApp.getThreadLocalObject("foo");
if (tl_obj.isNull()) {
tl_obj.set(new obj());
}
Object obj = tl_obj.get();
Note, the lines in red are always needed anywhere/anytime this class is used.
Method Summary |
java.lang.Object |
get()
|
boolean |
isNull()
|
static void |
main(java.lang.String[] args)
|
void |
set(java.lang.Object cal)
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ThreadLocalObject
public ThreadLocalObject()
get
public java.lang.Object get()
set
public void set(java.lang.Object cal)
isNull
public boolean isNull()
main
public static void main(java.lang.String[] args)
throws java.lang.Exception
- Throws:
java.lang.Exception