Hello! I tried the follwoing simplest code of running a thread in a servlet but it does not seem to.
Apache displays a blank page as if nothing happens. I just want my doGet method to provide a seperate response for each incoming request. Could you please help me? Waiting for reply....... Thank you. Fedai
[Edit by Dave: Code tags added] [ March 26, 2006: Message edited by: David O'Meara ]
I just want my doGet method to provide a seperate response for each incoming request. The Servlet container will already do this for you. It manages calling your Servlet with a separate thread for each request (and response).
ak pillai
author
Ranch Hand
Joined: Feb 11, 2006
Posts: 288
posted
0
As david has suggested Servlets are inherently multi-threaded. It will use a pool of threads to handle incoming requests. This is why Servlets are more efficient that CGI scripts. It is also not recommended if not forbidden to start new threads within Servlets like timer threads etc.
You wouldn't see the anything on the browser (as a response to your request).
That's because you've delegated the responsibility of delivering the output stream to another thread (i.e., not the Servlet's own thread).
And because you've dealt with using another thread, you cannot be certain when that new thread will write the output to the browser; it may sleep for a moment or will have the chance to run immediately as that with the Servlet's thread (which normally has the higher priority among others within the Servlet Context, a.k.a., servlet container.
BUT if you really want to see the result, try to click on the *refresh* button and you should be able to see the output this time.
Cheers.
Originally posted by fedai gandjaliyev: Hello! I tried the follwoing simplest code of running a thread in a servlet but it does not seem to.
Apache displays a blank page as if nothing happens. I just want my doGet method to provide a seperate response for each incoming request. Could you please help me? Waiting for reply....... Thank you. Fedai
[Edit by Dave: Code tags added]
[ March 26, 2006: Message edited by: David O'Meara ]