Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread running withing a servlet

 
fedai gandjaliyev
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags.

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
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Eduardo Dela Rosa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi fedai,

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 ]
 
fedai gandjaliyev
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see everything now!
Thank you very much!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic