• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Timing events in a servlet

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Suppose one wishes to let a servlet run a certain routine once every day or week, how would one do this? Currently, servlets get "unloaded" from the engine when they haven't been called for a while. Do you have to keep it up, or can you do some other nifty things?
PS: We use JRun, if that's any help.
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlets only run in response to requests -- they are not "programs", so the only way you could do this is to have some process submit a periodic servlet request.
I have my doubts about this "servlet unloading" thing, since a servlet is normally expected to be able to initialize its global state at startup or first reference (depending on option) and depend on global state forever after, so the worst that should happen is serialization, and that would have to be done transparently.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I recently had to build a client-side utility that could automatically upload a file to a servlet on a daily basis without any user interaction. What I did was use the java.io classes to read the file off the client machine and the java.net.HttpUrlConnection and related classes to send the data to the servlet. Then I simply used an O/S specific scheduler to run this program on a daily basis (for NT use Task Scheduler, for Unix use kron).
 
Thomas Goorden
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would it be possible to use a Timer class object in a servlet?
Of course it's supposedly a part of the Swing package, so it seems something weird to do, but would it work?
T.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a simple but effective "hack" for doing this which will work provided you have access to a UNIX server somewhere which you can set up cron jobs on. Have a daily (or weekly) cron task that does this:
lynx -dump http://yoursite.com/your/servlet > /dev/null
This will then cause the Lynx browser "access" your servlet at a set time every day, dumping the output HTML to /dev/null. It's not a very elegant solution but it works
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic