[My Blog]
All roads lead to JavaRanch
"Disappointing" and "Utterly Horrible" are not equal.
Tim Holloway wrote:No, you should not initialize logging in each and every JSP.
A relatively clean way to initialize logging is to create what I call a "null servlet", which is a servlet which has an init() method but no GET/POST handlers. Configure logging in the init() method, and make the servlet itself auto-start and be the first servlet to start. Everyone else can pick up from there.
You don't actually have to make a discrete servlet for this purpose as long as you already have something similar that you can add the log config process to. Just keep the design clean.
"Disappointing" and "Utterly Horrible" are not equal.
Tim Holloway wrote:Personally, I prefer to avoid adding listeners and other esoterica unless they're actually essential. If I can use basic building blocks, it's usually simpler, more understandable, and less likely to break unexpectedly when a new and improved standard comes out.
From a performance point of view, however, consider this: listeners are called continually. I mean, their name says it - they listen
In addition to the overhead of setting up and calling the listener (assuming you didn't need the listener for other purposes, too).
Tim Holloway wrote:Personally, I prefer to avoid adding listeners and other esoterica unless they're actually essential. If I can use basic building blocks, it's usually simpler, more understandable, and less likely to break unexpectedly when a new and improved standard comes out.
From a performance point of view, however, consider this: listeners are called continually. I mean, their name says it - they listen. However an init() method is only run once. So from a strictly performance point of view, a listener isn't the optimal choice. You definitely don't want to re-init logging each time the listener kicks off, and even though the overhead for checking so you only run the first time is fairly small, it's still overhead. In addition to the overhead of setting up and calling the listener (assuming you didn't need the listener for other purposes, too).
Bear Bibeault wrote:I'm going to have to respectfully but completely disagree with Tim here. "Null servlets" for initialization were a hack to perform initialization prior to the introduction of context listeners. A context listener is now the correct way to perform one-time initialization at context start.
manish sahni wrote:While implementing null servlet, i have found that their was not significant improvement in the performance time as compared to the
ServletContext Listeners
the initialization is needed only once
hack to perform initialization prior to the introduction of context listeners. A context listener is now the correct way to perform one-time initialization at context start.
Cheers,
Naren
(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Bear Bibeault wrote:I would very very surprised if there were any significant performance impact one way or the other. There difference comes down to that one way is an old-fashioned hack, the other is the conventional and intended mechanism.
"Disappointing" and "Utterly Horrible" are not equal.
Tim Holloway wrote:Well, I prefer the term "kludge" for that kind of stuff. A "kludge" in my dictionary is something that works, but isn't the ideal approach.
I am a man of mystery. Mostly because of this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|