|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I'm investigating JSP and servlets for a large project, and would like to know whether servlets can be scheduled to run automatically on the server?
I would like to achieve similar fuctionality to Lotus Domino agents which can be scheduled to run at for example midnight, or every hour etc. Also can JSP fetch an external URLs raw HTML and assign it to a variable? Many thanks JohnnyJazz |
|
#2
|
|||
|
|||
|
You could turn your servlet into a thread:-
public class TimerServlet extends HttpServlet implements Runnable Then in the init you can set up your variables:- public void init(ServletConfig config) throws ServletException Then in the run method:- while( true ) { // run forever.... try { theDate = new Date(); // -------- Calendar rightNow = Calendar.getInstance(); int currentHour = rightNow.get(Calendar.HOUR_OF_DAY); int currentMinute = rightNow.get(Calendar.MINUTE); int currentDayOfWeek = rightNow.get(Calendar.DAY_OF_WEEK); if ((currentHour == previousRunHH) && (currentMinute == previousRunMM)) { // Thread.sleep(2000); // try again in 2 seconds } else { code to do something } } catch (Exception e) { println(logPrefix() + ":run() Exception [" + e + "]"); } // try() } // end while } // now you could just sleep fo an hour after adjusting to get to the first round hour... |
|
#3
|
|||
|
|||
|
Also forgot to mention you can specify Autoload in your application server, I use IBM WAS/VAJ and this loads your server which because it's now a thread will be initialized and you will now run....
Not to sure about the URL though... |
|
#4
|
|||
|
|||
|
I just noticed you are from Liverpool, Say hi to my mum, she lives in Stoneycroft, I left there over twenty years ago and ended up here.
Peter. |
|
#5
|
|||
|
|||
|
Thanks for the reply Peter.
Servlets/JSP is looking a real promising solution as it looks like it can accomodate all our requirements more efficiently. What would be advantageous is if you knew where i could download a complete programmers guide to using JSP/servlets which lists syntax, classes, code examples, etc, preferably in PDF format. I'll shout hi to your Mum - i'm in Tuebrook. Cheers JohnnyJazz |
|
#6
|
|||
|
|||
|
We use servlet/Jsp's a lot, and I mean a lot, I have yet to come across anything we can not do (Internet wise) with this env. I like to think of a servlet as the TSR of java programming, as you get an enormous amount of support from the servlet environment.
If you can spare some money, I know I did'nt have much in TueBrook, the O'Reilly books, and there is a servlet ver 2 book out now, are really good. URL is a good resource for documentation/samples. keep the faith... |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Can you schedule servlets to run automatically |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|