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

270
Visualizações
Spring Schedule task for specific time at runtime

Does anyone has any experience with task scheduling in Spring? I understand you can schedule for a fixed time period or interval using annotations https://spring.io/guides/gs/scheduling-tasks/ But I was wondering if anyone knows how to do this using dynamic user input at runtime. For example a user schedules an email to be sent at 5:02pm exactly, is there a way add a new task dynamically using that as a time?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

  1. Collect user input and store it in DB as date/time, for example, we can call that value as NEXT_SEND_TIME.

2.Annotate mail sending method with @Scheduled as below, this method will be called automatically( by spring) for every 5 seconds (5000 ms).

3.Get current time and compare it with NEXT_SEND_TIME.

4.If current time is greater than NEXT_SEND_TIME , then trigger email for that user.

@Scheduled(fixedDelay=5000)
public void sendMail() {
    // do step 3 & 4 here
}
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