Terracotta-OSS / offheap-store

A library that provides a set of map and cache implementations that store data outside of the normal Java heap
Apache License 2.0
90 stars 46 forks source link

MappedByteBufferSource's ASYNC_FLUSH_EXECUTOR never shut down #38

Open ljacomet opened 8 years ago

ljacomet commented 8 years ago

org.terracotta.offheapstore.disk.paging.MappedPageSource.ASYNC_FLUSH_EXECUTOR is an instance of org.terracotta.offheapstore.util.Retryer and owns an executor which is not shut down.

This is my ugly workaround:

Field retryerField = MappedPageSource.class.getDeclaredField("ASYNC_FLUSH_EXECUTOR");
retryerField.setAccessible(true);

Retryer retryer = (Retryer) retryerField.get(null);

Field executorField = Retryer.class.getDeclaredField("executor");
ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor) executorField.get(retryer);

executor.shutdown();

Copied from ehcache/ehcache3#1444

chrisdennis commented 8 years ago

The likely way to fix this is to not shutdown the executor on "final shutdown", but instead shut it down when it becomes idle, and then get restarted again on the next usage.

sgup432 commented 7 months ago

I think this issue is related to https://github.com/ehcache/ehcache3/issues/3204

sgup432 commented 7 months ago

I am guessing we should shutdown the executor like below? @chrisdennis

class MappedPagedSource {
  public synchronized void close() throws IOException {
        try {
            this.channel.close();
            ASYNC_FLUSH_EXECUTOR.shutdown(); // shutdown the retryer like this?
        } finally {
            this.raf.close();
        }

    }
}