Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to write a threaded servlet?  RSS feed

 
archana vishwanath
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Can any throw some light on this?
My Requirement is like this..
I want to run a servlet constantly for all the 24 hours,performing some action.
i.e as soon as the doget/post is invoked it should(say for now just let it print some text in the browser).And it should do this till the time I close the browser.When I try to do this using a while loop and threads ,the system is getting hangged.
Am I doing some thing wrong?or is it something Illegal to run a continious while loop in a browser?
 
TV KUMAR
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Archana,
i don't think we can continuously keep flushing the data to the browser. if you use a loop which cannot be terminated, then it is definitely going to get hanged because it is going to keep the container busy always. One thing you can do is to call the servlet for every few seconds/minutes.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HTTP convention is designed for a request/response cycle, not a continuously running output stream. Browsers are also designed for this cycle. What exactly do you want to be getting on the client side?
Bill
 
Gowrishankar Mudaliar
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you are continuously writing the response, the response stream is not flushed and the page load would not be completed until you close the stream.
What you can try alternatively is use a concept called as server push(which is not exactly similar to what you are doing), where in the server pushes the data to the page.
Further, in your web page, take this feed in a seperate frame or an iframe, so that other parts are not affected.
chek this link for reference
http://skaiste.elekta.lt/Books/O'Reilly/Bookshelfs/books/javaenterprise/servlet/ch06_03.htm
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't do this from the server side. You need to poll from the browser side instead. Check out my article in this month's JavaRanch Journal for details on doing that.
Kyle
 
Jose Zaleta
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An option for having a web page self refresh itself is the HTML REFRESH meta tag, here's the code:

<meta http-equiv="refresh" content="2;url=http://your.url.com/">
2 is the number of seconds until the page is redirected.
The url is the url that will be loaded.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!