Johnny Kewl wrote:
>> So, what exactly does it mean when we say that Tomcat is thread
safe >> for
>> requests.
>> Tomcat creates a new thread for each request, so somehow my static
>> methods
>> are then thread safe (incdirectly, since it is managed by Tomcat).
I actually searched all over to try find something for you.... this
looks ok
http://www.codestyle.org/java/servlets/faq-Threads.shtml
But here my un-scientific way of thinking about it...
When tomcat sends a thread into your doGet method...
All those local variables in that thread are ok...
So I think about it as each thread being a lane on a big freeway/highway...
So yes you right in a way... Tomcat isnt allowing those local method
variables to get mixed up...
but the second you decalare a static method or static variable... you
had better be sure its thread safe.
What happens to that highway is that all the lanes merge into one, and
every car has to go through it...
When you add synchronized... your 30 lane high way becomes a single lane
and its one car at a time...
You dont want to add synchronized because here you have the TC guys gone
thru all the hassle of making sure you can have a 30 lane highway... and
you bang it into one lane.... so new is better because each lane gets
its own engine... and java is pretty damn good at garbage collecting,
that little bit of memory is a blip on the radar screen...
You got to really know what your code is doing when its static... you
got to know its thread safe, and it can be really hard to see that 30
car pile up coming on the highway ;)
My way of thinking about this stuff..... mad science - chapter 1 ;)
Johnny, you really have your own style of writing, to which we've all
gotten used to on this list.
But this one was really nice. Very understandable and fun.
Thanks.
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]