Hi all,
Here's my understanding of handling
thread safety wrt
Servlets. The question follows..
For each client request, the Servlet container spawns a new thread which inturn calls the service() method of the Servlet. Lets say, the thread has a run() method within which there's a statement like: servlet.service(request, response); This is all taken care of by th servlet container. As a programmer, our job is to make sure the doGet()/doPost() are thread-safe.
Now, consider a general situation where we have a thread class, multiple instances of which are created in some other class. Lets say, under the run() method of this thread, there is a call to some library function in the
Java API (similar to how the service() of Servlet gets called). In this case, how do we ensure that the Java API function is thread-safe? In general, is the Java API designed to handle thread safety?
I hope I made myself clear. Have I got something fundamentally wrong, or is this a valid question?
Thanks!