Scheduler does not load at application start

Asked

Viewed 47 times

0

I’m trying to create a simple task scheduler using EJB, but as a result it is not clicking at the beginning of the application, which would be through the annotation @Startup. Utilise jdk 1.8 wildFly 11.0.

Also, on the console of wildFly no error appears, neither Warning. I don’t know what might be going on. Could anyone help me? Or would they have a hint of what might be? Would have some configuration in wildFly?

My Scheduler class.java

import javax.ejb.Schedule;

import javax.ejb.Singleton;

import javax.ejb.Startup;


@Singleton

@Startup

public class Agendador {

    @Schedule(hour = "*", minute = "*", second = "*/10", persistent = false)
    void agendado() {
        System.out.println("verificando serviço externo periodicamente");
    }
}

1 answer

2

Your Bean is being loaded but will only start after configured time.

You can confirm this by adding the @Postconstruct Annotation:

package br.com.exemplo.agendador.servico;

import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
import javax.ejb.Startup;

@Singleton
@Startup
public class Agendador {

    private static final Logger LOG = Logger.getLogger(Agendador.class.getName());

    @PostConstruct
    public void init() {
        LOG.info("inicializado");
    }

    @Schedule(second = "*/10", minute = "*", hour = "*", persistent = false)
    public void agendado() {
        LOG.info("verificando serviço externo periodicamente");
    }

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.