Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

549
Views
Schedule task dynamically, in Springboot application

In a spring-boot application, I need to create a scheduled task that executes an exposed method (in the application domain).

Through the graphical interface, the user can configure the execution time and periodicity.

I already have this part.

The problem is to know if using quartz or similar library is possible to program the task and to be reprogrammed if the user modifies the configuration.

Please can you give me documentation about it so I can configure it this way.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

you can use @Scheduled annotation of spring. You can annotate any method on the spring component by specifying the delaystring ,i.e. the interval it should be running after. This can be configured in the properties file. To specify interval you can use "fixedRate" or "fixedDelay".

fixedRate- Executes the new run even if previous run of the job is still in progress.

fixedDelay-controls the next execution time when the last execution finishes.

This had helped me in the past.

  1. https://spring.io/guides/gs/scheduling-tasks
  2. https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/scheduling/annotation/Scheduled.html

1.You can create the JOB class containing the task to be done:

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class MyScheduledTask {

    private static final SimpleDateFormat currentTime = 
        new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

    @Scheduled(fixedRate = 2000) //interval in millisconds
    public void doSomeTask() {

        System.out.println("doSome task exceuted at " 
            + currentTime.format(new Date()));

    }
}

2.Main Spring boot class
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class Application {

    public static void main(String[] args) {

        SpringApplication.run(new Object[] { Application.class }, args);

    }

}

Hope this helps you a bit.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!