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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:46:09+00:00 2026-06-07T03:46:09+00:00

Is it possible to call a method in java at specific time? For example

  • 0

Is it possible to call a method in java at specific time? For example of I have a piece of code like this:

class Test{

    public static void main(String args[]) {
        // here i want to call foo at : 2012-07-06 13:05:45 for instance
        foo();
    }
}

How this can be done in java?

  • 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-07T03:46:10+00:00Added an answer on June 7, 2026 at 3:46 am

    Using a java.util.Timer class you can create a timer and schedule it to run at specific time.

    Below is the example:

    //The task which you want to execute
    private static class MyTimeTask extends TimerTask
    {
    
        public void run()
        {
            //write your code here
        }
    }
    
    public static void main(String[] args) {
    
        //the Date and time at which you want to execute
        DateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = dateFormatter .parse("2012-07-06 13:05:45");
    
        //Now create the time and schedule it
        Timer timer = new Timer();
    
        //Use this if you want to execute it once
        timer.schedule(new MyTimeTask(), date);
    
        //Use this if you want to execute it repeatedly
        //int period = 10000;//10secs
        //timer.schedule(new MyTimeTask(), date, period );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A Java method call may be parameterized like in the following code: class Test
Possible Duplicate: what is wrong with this call to the java method? The following
any idea how (if even possible) to call java method with optional parameters from
Is it possible to call a class method of all objects in a list?
Possible Duplicate: Why is the 'this' keyword required to call an extension method from
When overriding a method in Java is it possible to call the original one.
This is something like Reflection where you can call a method simply by its
I would like to create an equivalent if this Java method as PL/SQL function
I've a Runnable class , Is it possible to call this runnable class inside
Possible Duplicate: Scala equivalent of Java java.lang.Class<T> Object Hi all, I can not call

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.