简体   繁体   中英

Clear cache of @Schedule in EJB

I have a singleton class that perform an task in some time interval. When the application starts its all fine, the task is run in right period and that interval is enough suck that any task isn't overlap.

The class is show bellow:

@Singleton
@Startup
public class BOTAnalisaSituacao {
    public BOTAnalisaSituacao() throws FileNotFoundException {
    }

    @Schedule(second = "0", minute = "*/1", hour = "*")
    public void analisar() throws Exception {
        System.out.println("Starting");
        System.out.println("DONE");
    }
 }

The web container used is Wildfly 10.

The problem is, when the application is started after one hour down, for example, the task is executed sequentially, in this case all 60 calls, after that the 1 minute period is restored by itself. Do I have to clear any cache to avoid suck behavior?

Timers are persistent by default. If the server is shut down or crashes, persistent timers are saved and will become active again when the server is restarted, If a persistent timer expires while the server is down all lost timers will be called. Non-persistent programmatic timers are created by calling adding persistent=false to annotation:

@Schedule(second = "0", minute = "*/1", hour = "*",persistent=false)
    public void analisar() throws Exception {
        System.out.println("Starting");
        System.out.println("DONE");
    }

source: http://docs.oracle.com/javaee/6/tutorial/doc/bnboy.html#bnbpa

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM