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

not able to execute servlet at specific intervals  RSS feed

 
dhanunjaya kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am,writing a servlet ,i want to run this servlet at specific intervals or at a given time it was not working.

i am using the following code
<servlet>
<servlet-name>aa</servlet-name>
<servlet-class>aa</servlet-class>
<run-at>16:56</run-at>
</servlet>
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <run-at> attribute is not a standard part of the Servlet spec.
I think it is something Resin added to their server and I, personally, don't think it's a good idea.

Another approach is to use a timer or the Quartz libraries (started from a contextListener).
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the whole idea of a servlet is to respond to a request, perhaps the function belongs in a "helper" object having its own thread and timer mechanism. Make it an object that can be tested outside the servlet environment and debugging will be easier.
Bill
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet works on client request.But fi you want to so something in specific interval of time from a web container..you can write a servlet..load that on startp..write and start a thread that would run your task in specific interval of time.You can use java timers also.Put this code in the init().
 
Vijay Kumar koganti
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Rahul,

Orginal:
-----------------------------------------------------------
..write and start a thread that would run your task in specific interval of time.You can use java timers also.Put this code in the init().

Rahul, can you give a little light on how we would be able to achieve this .

Thanks,
vijay kumar k.
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am,writing a servlet ,i want to run this servlet at specific intervals or at a given time it was not working.

does your servlet spit out any html? if so, just put this within the <html><head> tags.

<meta http-equiv="refresh" content="600">

this will refresh the current page every 600 seconds.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Lynette Dawson:

does your servlet spit out any html? if so, just put this within the <html><head> tags.

<meta http-equiv="refresh" content="600">

this will refresh the current page every 600 seconds.


It seems to me that relying on a browser to stay open and aimed at the webserver is a very roundabout way of achieving simple 'cron like' task.

http://en.wikipedia.org/wiki/Rube_goldberg
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!