Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8871847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:05:21+00:00 2026-06-14T18:05:21+00:00

I am using the cron4j library for scheduling a program. Here is my code:

  • 0

I am using the cron4j library for scheduling a program. Here is my code:

public class Main {
public static void main(String[] args) {
    // Declares the file.
    File file = new File("cron4j.txt");
    // Creates the scheduler.
    Scheduler scheduler = new Scheduler();
    // Schedules the file.
    scheduler.scheduleFile(file);
    // Starts the scheduler.
    scheduler.start();
    // Stays alive for five minutes.
    try {
        Thread.sleep(5L * 60L * 1000L);
    } catch (InterruptedException e) {
        ;
    }
    // Stops the scheduler.
    scheduler.stop();
}
}

Inside the “cron4j.txt” file I have set my program to run every minute.

  1. Must this file (class Main) with the object scheduler be running in order for the program in the file to be executed every minute?
  2. Or once I run this once will the scheduler pass off this job to the operating system?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:05:22+00:00Added an answer on June 14, 2026 at 6:05 pm

    The program must be continuously running. Cron4j is just hiding the scheduling for you but in reality is a bunch of threads sleeping and waiting for the time to come for execution. The operating system just sees your program as a normal one continuously running.

    In order to use the operating system’s scheduling mechanisms, you do not use Cron4j but use crontab (on linux) or the task scheduler on Windows.

    One more sophisticated scheduler for Java, which is more considered the Industry standard is Quartz Scheduler. However the concept is the same, your program needs to be running for the scheduled tasks to happen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
Using import datetime in python, is it possible to take a formatted time/date string
Using C#, I need a class called User that has a username, password, active
Using EF Code First I have an model object that has multiple properties that
Currently, using cron4j , i am able to schedule execution of an event at,
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange
Using the HTML5 File API I can get the Binary String representation of a
Using CMake I want to check if a particular function (cv::getGaborKernel) from OpenCV library
Using server-side C#, how can I convert a querystring to a JSON string of
Using the classic code snippet: if (x & (x-1)) == 0 If the answer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.