Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Running Servlet file on specific date/time automatically  RSS feed

 
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I want to inovke/run myServlet file on one specific date and this process will be repeated

Thanks & best regards
 
Bartender
Posts: 4179
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want a task to run at a specific time, why are you making that task a Servlet? In my opinion, the task itself should be a stand-alone application that you can schedule using your operating system's scheduler. If you need it to send info to/get info from the web application then using a request to a Servlet isn't a bad idea...

That being said, you have a few choices:
1) Have a Timer/TimerTask that starts when the web application loads and makes a call to the Servlet of interest.
2) Make a stand alone Java application that you schedule using the operating system's scheduler (or some other scheduling tool, there are lots of them) that makes a request to the Servlet of interest.


 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Steve Luke wrote:
2) Make a stand alone Java application that you schedule using the operating system's scheduler (or some other scheduling tool, there are lots of them) that makes a request to the Servlet of interest.



I liked this idea but can you please get me more details that how can I proceed?

Thanks for your prompt reply
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will probably want to read the API for java.net.HttpURLConnection, and java.net.URLConnection. Also, you should read the Sun Java Tutorial for URLConnections.

You might also look at the Apache site for their HttpClient package. It makes working with Java apps that communicate with web servers a lot easier to use - especially if there is a lot of data to transfer.
 
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is this servlet going to do? I'm curious why it is a servlet in the first place.

Having said that I once wrote a server program that ran in tomcat on a regular basis and collected information on all of our running database servers. The advantage of running it in tomcat was that we could use jsp's and servlets to manage the application. We used Quartz to perform the timing. If you are familiar with cron it can allow you to schedule tasks with the same syntax you would use in crontab.
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

steve souza wrote:What is this servlet going to do? I'm curious why it is a servlet in the first place.

Having said that I once wrote a server program that ran in tomcat on a regular basis and collected information on all of our running database servers. The advantage of running it in tomcat was that we could use jsp's and servlets to manage the application. We used Quartz to perform the timing. If you are familiar with cron it can allow you to schedule tasks with the same syntax you would use in crontab.



I seen in plesk crontab module but never used it. How can I get, install and use Quartz with my tomcat?

thanks & best regards
 
steve souza
Ranch Hand
Posts: 862
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to look at the documenation. Here is the link. They have a tutorial link of this page.
http://www.opensymphony.com/quartz/

Here is a little info about how it works like cron from their javadocs.

http://quartz.sourceforge.net/javadoc/org/quartz/CronTrigger.html

Quartz is powerful.
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!