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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:46:55+00:00 2026-05-30T13:46:55+00:00

I want to execute a job everyday 2PM. Which method of java.util.Timer I can

  • 0

I want to execute a job everyday 2PM. Which method of java.util.Timer I can use to schedule my job?

After 2Hrs, run it will stop the job and reschedule for next day 2PM.

  • 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-30T13:46:56+00:00Added an answer on May 30, 2026 at 1:46 pm
    import java.util.Calendar;
    import java.util.Date;
    import java.util.GregorianCalendar;
    import java.util.Timer;
    import java.util.TimerTask;
    
    
    public class MyTimerTask extends TimerTask {
        private final static long ONCE_PER_DAY = 1000*60*60*24;
    
        //private final static int ONE_DAY = 1;
        private final static int TWO_AM = 2;
        private final static int ZERO_MINUTES = 0;
    
    
        @Override
        public void run() {
            long currennTime = System.currentTimeMillis();
            long stopTime = currennTime + 2000;//provide the 2hrs time it should execute 1000*60*60*2
              while(stopTime != System.currentTimeMillis()){
                  // Do your Job Here
                System.out.println("Start Job"+stopTime);
                System.out.println("End Job"+System.currentTimeMillis());
              }
        }
        private static Date getTomorrowMorning2AM(){
    
            Date date2am = new java.util.Date(); 
               date2am.setHours(TWO_AM); 
               date2am.setMinutes(ZERO_MINUTES); 
    
               return date2am;
          }
        //call this method from your servlet init method
        public static void startTask(){
            MyTimerTask task = new MyTimerTask();
            Timer timer = new Timer();  
            timer.schedule(task,getTomorrowMorning2AM(),1000*10);// for your case u need to give 1000*60*60*24
        }
        public static void main(String args[]){
            startTask();
    
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I return a java.util.concurrent.Future object with a Receipt object and only use
From a java program, I want to execute a script which reads an input
I want to execute a php-script from php that will use different constants and
I want to execute a script every 30mins, but i want to use it
I want to execute a batch file from a java program. I am using
I want to dynamically add triggers to a job, but can't find any helpful
I want to schedule a job in Jboss and websphere server. I have a
I am using a CommandLineJobRunner to execute a spring batch job. I want to
I need a timer equivalent which will periodically execute some specific actions (e.g. updating
I want to execute a call to a particular method every minute, and it

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.