package net.ranides.assira.ee;

import net.ranides.assira.collection.maps.CacheMap;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;

@Singleton
@Startup
public class CacheMapCleaner {

    private Thread thread;

    @PostConstruct
    public void init() {
        thread = new Thread(() -> CacheMap.cleanup(true), "assira.ee cache cleanup");
        thread.setDaemon(true);
        thread.start();
    }

    @PreDestroy
    public void destroy() {
        thread.interrupt();
    }

}
