Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-04-2007, 12:37 PM
Senior Member
 
Join Date: Nov 2007
Posts: 111
bugger is on a distinguished road
Scheduling a task
I have a class written in Java that connects to a MySQL database and updates few tables. It works perfectly fine.

I have to run it after every 4 hours. I want to automate it using some scheduling. How can this be done. Please help me out.

Thanks a lot.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-04-2007, 12:59 PM
Senior Member
 
Join Date: Jun 2007
Location: Bali, ID
Posts: 102
wsaryada is on a distinguished road
You can create a java.util.TimerTask implementation that do your database update. Then run this task using java.util.Timer class every 4 hours as you required. I have a small example on how to use these classes here: How do I create a scheduled task using timer? You can just modified it to fit your requirement.
__________________
Website:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Blog:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-04-2007, 02:21 PM
Senior Member
 
Join Date: Nov 2007
Posts: 111
bugger is on a distinguished road
Thanks mate.
But I don't wan to run the code my self. I want some background process to keep monitoring the time and after 4 hours, it should trigger the class.

Something like Window Scheduling.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-04-2007, 02:32 PM
Senior Member
 
Join Date: Jun 2007
Location: Bali, ID
Posts: 102
wsaryada is on a distinguished road
Well, there must be an application to execute the job right. This application can be your own java class or maybe you can also execute it from the windows scheduler. If it can run any command line you can ask the windows scheduler to execute java command to run your class.

There is also some great library for scheduling such as Quartz that you can also use for creating the scheduler.
__________________
Website:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Blog:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PLZ...PLZ!!!HELP ME TO WRITE THE TASK 2's CODES hhoa87 Advanced Java 3 03-23-2008 01:50 AM
java : how to hide application icon from a task bar yogeshagashe Advanced Java 0 03-12-2008 03:05 PM
Scheduling tasks using Threads Java Tip Java Tips 0 12-11-2007 12:24 PM
String Manipulation Task hiranya New To Java 1 11-19-2007 01:07 PM
Task Blocks 0.5 johnt Java Announcements 0 08-08-2007 10:43 PM


All times are GMT +3. The time now is 11:40 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org