Cetsoft / imcache

Imcache is a Java Caching Library.
Other
129 stars 40 forks source link

JVM does not exit while running OffHeapCache given in the examples code #4

Closed sureshbabuinfo closed 9 years ago

sureshbabuinfo commented 9 years ago

I am trying to integrate IMCache offheap with web application. When I ran the samples given(Added the code below), JVM never exits after successfully executing the code.

OffHeapByteBufferStore bufferStore = new OffHeapByteBufferStore(8388608 ,10, 1);
    final Cache<String,String> offHeapCache = CacheBuilder.offHeapCache().storage(bufferStore)
  .cacheLoader(new CacheLoader<String, String>() {
        public String load(String key) {
            return cacheDao.load(key);
        }
    }).evictionListener(new EvictionListener<String, String>() {
        public void onEviction(String key, String value) {
            cacheDao.store(key, value);
        }
    }).build();

    for(int i = 0; i < 1000; i++){
        offHeapCache.put("key-" + i, "value - " + i);
    }  
    System.out.println(offHeapCache.get("key-" + 100));

How can I integrate offheap cache with my web application?

Here is the stack overflow discussion link:

http://stackoverflow.com/questions/31145249/integrate-imcache-with-web-application?noredirect=1#comment50346715_31145249

yusufaytas commented 9 years ago

Hello JVM doesn't exit because there are background threads which takes care of garbage collection of offheap.

ben-manes commented 9 years ago

@sureshbabuinfo is indirectly asking for the background threads to be daemons. Since off-heap data is not accessed or persisted across JVM instances, and the OS will cleanup the process's resources, it should be safe to exit as daemon threads.

yusufaytas commented 9 years ago

Fixed the issue.