This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Scheduler Servlet  RSS feed

 
priti manas duddilla
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a J2EE Web Application.
One of my requirements is: I need to write a scheduler and configure it (in Web.xml, DD ?). This scheduler will run twice every day, and it should kick off a java job.
The job is, it should get a JDBC connection with UDB DB2 table and extract data, and should push the extracted data (after modifying as per requirements) to Mainframe DB2 tables.
I very much appreciate, if some one help me with the above requirement.
May be a code snippet or a link could help.

Thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The java.util.Timer and TimerTask classes can be used to schedule repeated code executions. A small sample is here, and their respective javadocs have much more.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or you could opt for quartz scheduler from opensymphony.com

@ http://www.opensymphony.com/quartz/
 
priti manas duddilla
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Kumar.
I have researched on Quartz, but i am not supposed to use it as, it is a open source software.

Thank you Ulf,It certainly helps.

This is what i have done so far...

public class LoadSchedulerService extends TimerTask {

Long delay = 5000; // delay for 5 sec.
Long period = 43200000; // repeat every 12 hours.
Timer timer = new Timer();

timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
//Establishing connection with UDB Database
//Extract Data from UDB Database
//Modify Data
//Establishing connection with MainFrame Start
//Updating the Mainframe DB2 Tables }
}, delay, period);


Can you please let me know, where i have to configure this java file, so that it loads on server startup and runs every day. (Should it be a servlet which extends TimerTask ? just a thought).
 
Leandro Dantas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can create the timer on servlet started by the container using on your web.xml

[ January 09, 2008: Message edited by: Leandro Dantas ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Leandro Dantas:
You can create the timer on servlet started by the container using on your web.xml


[ January 09, 2008: Message edited by: Leandro Dantas ]


These days, we use context listeners for things like this and use servlets only for responding to HTTP requests.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!