I’m looking at how to fix the case where multiple servlet requests hit
around the same time on startup, which invariably causes classes to
not get autoloaded correctly when multiple threads are involved.
The approach I’m looking at right now is to use a atomic global
integer counter to track the state of the first call to the servlet
- If the counter is 0, set it to 1 and let the init run. When init is
finished, increment the counter to 2.
- If the counter is 1 on entry, wait until it has incremented to 2,
then run init.
- If the counter is 2 on entry, let init run normally
One thing I don’t know is what tomcat’s behavior is if I just raise an
exception in init instead of waiting. I’m assuming it might just kill
the thread, start a new one, and call init on it. This could cause a
ton of cpu usage until init stops throwing exceptions as tomcat spins
up one thread after another.
Any suggestions/advice appreciated…
Also, I’m working with 1.0.9. Later versions broke custom logging and
I don’t have time to sort that one out right now.