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

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

  •  01-09-2022
  •  | 
  •  

문제

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

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top