Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize Ejb Timer Schedule without Rebuilding War

I am using a ejb timer in my code as follows:

import org.apache.logging.log4j.Logger;
import javax.annotation.Resource;
import javax.ejb.Schedule;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.inject.Inject;

@Singleton
@Startup
public class Notifier {

    @Inject
    Logger LOG;

    @Resource(mappedName="java:jboss/mail/Default")
    private Session mailSession;

    @Schedule(minute = "0", hour = "*", persistent = false)
    public void notify()  {

    }
}

I would like to be able to reconfigure the scheduler without having to rebuild and upload the resulting war to the server each time I decide that I need to tweak the schedule.

How do I do this?

like image 486
Baz Avatar asked Oct 30 '22 06:10

Baz


1 Answers

You could use a system property and the ScheduleExpression. Or you could use a programmatic EJB Timer.

Another option would be to use a ManagedScheduledExecutorService and use a Trigger to control the next run time. Again you could use a system property or just a configuration file that lives outside the application.

like image 146
James R. Perkins Avatar answered Nov 16 '22 08:11

James R. Perkins