39 Using Timeout with Cache Operations
When many threads access Coherence caches
concurrently, callers to Coherence cache operations can be blocked on common locks. This
blockage may lead to the accumulation of stuck threads. To help avoid these stuck
threads, Coherence uses an interruptible lock so operations can be interrupted after a
specified timeout interval. You can use the Timeout API to interrupt and
error out the blocking operation after the amount of blocking time exceeds the specified
timeout interval.
Here is an example of how to use the Timeout API to interrupt the
getCache
operation if it takes longer than the given two minute
timeout
interval:try (Timeout t = Timeout.after(2, TimeUnit.MINUTES))
{
NamedCache cache = CacheFactory.getCache("myCache");
}
catch (InterruptedException e)
{
// error out getCache() due to timed out.
}