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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:46:47+00:00 2026-05-27T16:46:47+00:00

I want to schedule a method call in Spring MVC to run after every

  • 0

I want to schedule a method call in Spring MVC to run after every two hours. This I can easily do via Spring 3.0 Time Scheduler. However, I want to kick the execution off only at a specific time of the day. That is, the method should only be invoked every 2 hours starting at a particular time.

For example – I want the method to run every 2 hours starting 6 AM.
The TimeScheduler interface has a scheduleAtFixedRate method which is overloaded to use startTime Date argument. I am not really sure how to use this.

Any idea how this can be achieved ?

  • 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-27T16:46:48+00:00Added an answer on May 27, 2026 at 4:46 pm

    You could take a look at the TaskScheduler interface. It provides a method scheduleAtFixedRate(Runnable task, Date startTime, long period) which returns a ScheduledFuture. You can use this with some simple Spring configuration:

    <task:scheduler id="scheduler" pool-size="10"/>
    

    This will create an instance of ThreadPoolTaskScheduler which implements TaskScheduler. Wire this bad boy into the class to call your specific method:

    public class MyClass {
        @Autowired
        private TaskScheduler scheduler;
    
        public void init() {
            scheduler.scheduleAtFixedRate(new Runnable() {
                public void run() {
                    myMethod();
                }
            }, new Date(), 1000 * 60 * 60 * 2); //This will start now and run every two hours
        }
    
        public void myMethod() {
            // the method you want to invoke
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a windows service which the user can schedule. i.e, the
I want to run a sql query on a specific schedule (weekly) and need
I want to execute a job everyday 2PM. Which method of java.util.Timer I can
I want to schedule events to happen for my users. Is there an efficient
I want to schedule the email with asp.net and C# code. what is basic
I am running a SVN server on my Windows Server and want to schedule
I want a way to be able to schedule callbacks, I want to be
Hai guys, I want to send scheduled mail every morning from my application and
I feel like I should know this but I've been stumped for hours now
I've got some old Excel VBA code where I want to run a task

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.