Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: How to schedule a Java Program for Background processing

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to schedule a Java Program for Background processing

    Dear Forum Members,

    Can anybody help me to schedule a Java program in background? That is, for example, I want to run a Java Program every day once at 3 AM (early in the morning).

    Kindly tell me process involved to achieve this.

    Thanks and regards,
    Ranga
    Java Programmer


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: How to schedule a Java Program for Background processing

    Well, do you mean you want to create a cron job that runs the actual java program every so often or do you mean you want to start a java program that stays up and running all the time but only executes a certain block of code every so often?

    // Json

  3. #3
    Junior Member
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to schedule a Java Program for Background processing

    We11 !

    I will explain the scenario. I have written a data download program in Java to download records of tables from a database to text files. Writing the download program is not a issue. But if I execute the program, it takes more than half-an-hour to finish executing due to data volume in tables. In fact, we want to download 15 tables from the database to text files. We cannot give this program to the end-user to run in foreground.

    To sort out this, I want my Java Program to start running automatically everyday once at 3 AM or 4 AM or 11 PM so that data download happens without end-user manually executing it.

    How can I schedule my data download Java program in background so that everyday we can ensure that all records from those 15 tables are downloaded without manually executing the program.

    We request you to help us with appropriate process of implementing this business requirement.

    Thanks and regards,
    Ranga.

  4. #4
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: How to schedule a Java Program for Background processing

    In that case I take it you should run a cron job.

    https://help.ubuntu.com/community/CronHowto

    That page there explains how to get up and running using crontab. Dont know what operating system you are running on though, but if you're on windows I'm sure there is a similar solution to setting up timed tasks, maybe even easier.

    // Json

  5. #5
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: How to schedule a Java Program for Background processing

    There are two simple methods:

    1. Use the native OS's task scheduler (if there is one) to start the task at the specified time. A quick google search for which OS you are interested in should do the trick here. This will not require your program to be constantly running in the background (though it is in a sleep state, it is still using up recources), and depending on the OS/implementation of task scheduling software, you can even get the OS to power-up the system and perform the task required.

    2. Use the Java Timer class to schedule tasks at either certain time intervals or at certain dates/times. Note that I think this method requires your Java program be running in the background constantly, but don't quote me on this.

  6. #6
    Junior Member
    Join Date
    Aug 2009
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Smile Re: How to schedule a Java Program for Background processing

    Thanks a lot for your suggestion. I will also search in Google to find any better way of doing it.

    Regards,
    Ranga.

Similar Threads

  1. Text Processing with Regular Expressions explained in Java
    By JavaPF in forum Java Programming Tutorials
    Replies: 3
    Last Post: February 8th, 2022, 05:16 PM
  2. Natural language processing in java
    By nikki. in forum Java Theory & Questions
    Replies: 5
    Last Post: March 19th, 2012, 11:34 PM
  3. Help with background and objects
    By Afromiffo in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 8th, 2010, 01:19 AM
  4. Background image on GUI
    By OBLITERATOR in forum AWT / Java Swing
    Replies: 3
    Last Post: March 5th, 2010, 12:10 PM
  5. JButton set background problem
    By ellias2007 in forum AWT / Java Swing
    Replies: 1
    Last Post: February 25th, 2010, 12:15 AM