fc.util
Class ThreadLocalCalendar
java.lang.Object
fc.util.ThreadLocalCalendar
public final class ThreadLocalCalendar
- extends Object
Useful to store thread-local calendar instances. 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 calendar
object. This allows multiple instances of this class in the webapp, with
each instance being able to get/set a seperate calendar. [If the methods in
this class were static, then only 1 calendar could be get/set per thread].
Each thread must remember to individually create a seperate
calendar instance and store it via the set method. The usage idiom
is:
//WebApp has a map of ThreadLocalCalendars and also a instance variable
//with a default ThreadLocalCalendar
ThreadLocalCalendar mycal = WebApp.getThreadLocalCalendar("foo");
if (mycal.isNull()) {
mycal.set(Calendar.getInstance());
}
Calendar cal = mycal.get();
Note, the lines in red are always needed every time this class is used.
ThreadLocalCalendar
public ThreadLocalCalendar()
get
public Calendar get()
set
public void set(Calendar cal)
isNull
public boolean isNull()
main
public static void main(String[] args)
throws Exception
- Throws:
Exception