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