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

148 views Asked by At

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");  
        }
    }

1

There are 1 answers

0
jpkroehling On BEST ANSWER

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