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 6929645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:20:40+00:00 2026-05-27T11:20:40+00:00

Without using Quartz, is there any option for Timer class or workaround to start

  • 0

Without using Quartz, is there any option for Timer class or workaround to start scheduled jobs even if the previous job is not finished?

Here’s sample code.

Job Scheduled for every 1 sec

public static void main(String[] args) {
  Timer timer = new Timer();
  Calendar date = Calendar.getInstance();
  timer.scheduleAtFixedRate(new UnitTest(timer), date.getTime(), 1000);
}

Job Performed

Each job has 2 second delay

public void run() {
    count++;
    int a = count; // to see which job is started and ended.
    System.out.println(this.now("HH:mm:ssSSS")+"- start "+count);
    try {
        Thread.sleep(2000);
    } catch (InterruptedException e) {}
    System.out.println(this.now("HH:mm:ssSSS")+"- end "+a);
}

Result – if the previous job is not finished, then the next job is not started.

12:14:21946 - start 1
12:14:23965 - end 1
12:14:23965 - start 2
12:14:25966 - end 2
12:14:25967 - start 3
12:14:27968 - end 3
12:14:27968 - start 4
12:14:29969 - end 4
12:14:29970 - start 5
12:14:31970 - end 5
12:14:31971 - start 6
12:14:33972 - end 6

How can I add this option for Timer class?

Quartz – Concurrent Option from http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/scheduling.html

By default, Quartz Jobs are stateless, resulting in the possibility of jobs interfering with each other. If you specify two triggers for the same JobDetail, it might be possible that before the first job has finished, the second one will start. If JobDetail classes implement the Stateful interface, this won’t happen. The second job will not start before the first one has finished. To make jobs resulting from the MethodInvokingJobDetailFactoryBean non-concurrent, set the concurrent flag to false.

EDITED SAMPLE CODE

public class TEST01 {

Timer timerTEST01 = new Timer();

public String[] start()
{
    try
    {
        timerTEST01.scheduleAtFixedRate(new TimerTask() {
            public void run() {
                Runnable r = new Runnable() {
                    public void run() {
                        //DoWork
                    }
                };
                Thread t = new Thread(r);
                t.start();
            }

        }, date.getTime(), 1000*60);

        return new String[]{"true", "Good Job!"};
    }
    catch(Exception e){}
    finally{}
}
}
  • 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-05-27T11:20:40+00:00Added an answer on May 27, 2026 at 11:20 am

    Instead of running the code directly at the timer, when the timer calls your method, spawn a new thread (or use a thread poll) to execute your task:

    public void run() {
        Runnable r = new Runnable() {
            public void run() {
                count++;
                int a = count; // to see which job is started and ended.
                System.out.println(this.now("HH:mm:ssSSS")+"- start "+count);
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {}
                System.out.println(this.now("HH:mm:ssSSS")+"- end "+a);
            }
        };
    
        Thread t = new Thread(r);
        t.start();
    }
    

    This will guarantee that every single job executes at the given time even if the previous one hasn’t executed.

    Also, make sure your code works inside an anonymous inner class, that count++ probably isn’t going to work.

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

Sidebar

Related Questions

Without using dynamic SQL, and other than an If ELSE is there any way
Without using any plugins, are there any built in function in jQuery or jQuery
Without using Javascript, is there a way to make a CSS property toggle on
Without using any third party program to do this (i.e. without VMware ThinApp, U3
How to check visited link using jquery without using any plugin please help to
Anyone know how to do this without using a third party program? If there
Without using boost::thread and boost::bind directly, is there a way to implement the equivalent
Without using any JavaScript library like JQuery, how do I show an error to
Without using ANT, is there a way to have Eclipse not prompt me for
without using any big web framework (just servlets), do you know a ready to

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.