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.
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.
Customer surveys are for companies who didn't pay proper attention to begin with.
Joined: Jun 27, 2001
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).
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.
Joined: Nov 23, 2001
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