Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

550
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda