Originally posted by Frank Carver:
Is from an exam or homework question? If so, I suggest that you have a go at working out the answer yourself and let us know here. Then we can help you clear up any confusion or misunderstandings. I'm not sure that just telling you the answer will help you learn and understand.
SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Originally posted by Veena Point:
Local variables are not affected by multiple threads.Only instance variables and static variables can be made thread safe by implementing SingleThread model.But again if we consider pool of servlet instances,singlethreadmodel fails.Correct me if I am wrong.
Veena
[ January 08, 2004: Message edited by: Veena Point ]
Originally posted by Frank Carver:
When a request is received for a servlet marked as SingleThreadModel the server can deal with it in one of three ways:
The server might create (and call init()) a completely new servlet instance just for this request, and destroy it as soon as the request is finshed. This is effective, but can be very slow. The server might create (and call init()) only one instance of the servlet and use it for all requests. In this case if a request for the servlet arrives while another one is still processing, the server must either queue the request, or return an error to the browser. The server might create more than one instance of the servlet, and if a request comes in while one instance is busy, the server will pass the request to an instance which is currently idle. This group of pre-created servlet instances is known as a pool, and is the most popular way for servers to handle this problem.
Originally posted by yogendra singh:
[QB]
one more techincal question is that when we implement singleThraedModel , they say it synchronized the service() method ...then how can be instance variable are thread-safe....
Becuase each thread operates on a separate servlet object.
Each thread operates seaparate servlet "object "??? in singleThreadModel we have only one "Object" or "instance" of servlet .... and when u say instance variable ... these are the variables which declare in the init () or declared in the service() method. ....
Each thread operates seaparate servlet "object "??? in singleThreadModel we have only one "Object" or "instance" of servlet .... and when u say instance variable ... these are the variables which declare in the init () or declared in the service() method. ....
Don't get me started about those stupid light bulbs. |