Make Wildfly Server perform task

2

I need to create a task executor where it will call a method from time to time, I saw an example and it became my implementation:

public class Agendador {

    private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);

    final Runnable beeper = new Runnable() {

        @Override
        public void run() {
            EncomendaController controller = new EncomendaController();
            controller.pesquisar();

        }

    };

    final ScheduledFuture<?> beeperHandle = scheduler.scheduleAtFixedRate(beeper, 0, 1, TimeUnit.MINUTES);

}

How can I make wildfly read this class to start performing this task?

    
asked by anonymous 30.03.2017 / 00:26

1 answer

3

Example for method funcaoAgendada() to be invoked every second:

@Singleton
public class Agendador {
    @Schedule(second = "*/1", minute = "*", hour = "*", persistent = false)
    public void funcaoAgendada() {
        System.out.println("Função Agendada em execução!");
    }
}

Your scheduler does not have to be @Singleton, it can be @Stateless and even @Stateful.

    
30.03.2017 / 00:38