I have a multi-threaded, high-performance and long-running process (I mean hours) in Spring. In order to allow this process to cancel I like to check periodically for the permission to cancel this process using a huge SQL.
@Service
public class CancelHolder {
@PersistenceContext
private final EntityManager em = null;
public boolean isCancel() {
return !em.createQuery("..<huge sql>..").getResultList().isEmpty();
}
}
This isCancel
is called about 20/sec/thread from about 100 threads make a total of 2000 calls per second.
Problem
If I use @Cacheable(value="cancelcache", sync=true)
the method is called once and stored forever.
Solution
I have to evict the cache every 1 second.
Question
How to evict the cache every 1 second?