Can an application server (like jboss or weblogic) call some methods every 'n' times

StackOverflow https://stackoverflow.com/questions/20563226

  •  01-09-2022
  •  | 
  •  

Frage

Hello everyone!
Help, please!
Can an application server (like jboss or weblogic) call some methods every, for example, 10 minutes?
I'll explain: would be an ear or a jar file deployed on server, and deployed project will every 10 minutes call some method which selecting from DB something? If it may be, can you give an example. Thanks!

Solution:

    import javax.annotation.PostConstruct;
    import javax.ejb.*;

    @Singleton
    @Startup
    @LocalBean
    public class ScheduledTask {

        @PostConstruct
        public void initialize(){
            System.out.println("ScheduledTask is inited!");
        }

        @Schedules({@Schedule(hour = "*", minute = "*", second = "*/60")})
        public void send() {
            System.out.println("print send every 1min");    
        }

        @Schedules({@Schedule(hour = "*", minute = "*/30", second = "*/60")})
        public void receive() {
            System.out.println("print receive every 30min");  
        }
    }

War es hilfreich?

Lösung

You can have a @Schedule annotation in an EJB, which instructs the application server to call it every N seconds/minutes/... .

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top