title: Guava CacheBuilder removal listener
body: <p>Please show me where I'm missing something.</p>
  
  <p>I have a cache build by CacheBuilder inside a DataPool. DataPool is a singleton object whose instance various thread can get and act on. Right now I have a single thread which produces data and add this into the said cache.</p>
  
  <p>To show the relevant part of the code:</p>
  
  <pre><code> private InputDataPool(){
  
      cache=CacheBuilder.newBuilder().expireAfterWrite(1000, TimeUnit.NANOSECONDS).removalListener(
              new RemovalListener(){
                  {
                      logger.debug("Removal Listener created");
                  }
                                  public void onRemoval(RemovalNotification notification) {
                                      System.out.println("Going to remove data from InputDataPool");
                                      logger.info("Following data is being removed:"+notification.getKey());
                                      if(notification.getCause()==RemovalCause.EXPIRED)
                                      {
                                          logger.fatal("This data expired:"+notification.getKey());
                                      }else
                                      {
                                          logger.fatal("This data didn't expired but evacuated intentionally"+notification.getKey());
                                      }
  
                                  }}
                      ).build(new CacheLoader(){
  
                          @Override
                          public Object load(Object key) throws Exception {
                                  logger.info("Following data being loaded"+(Integer)key);
                                  Integer uniqueId=(Integer)key;
                                  return InputDataPool.getInstance().getAndRemoveDataFromPool(uniqueId);
  
                          }
  
                      });
  }
  
  public static InputDataPool getInstance(){
          if(clsInputDataPool==null){
              synchronized(InputDataPool.class){
                  if(clsInputDataPool==null)
                  {
                      clsInputDataPool=new InputDataPool();
                  }
              }
          }
      return clsInputDataPool;
  }
  </code></pre>
  
  <p>From the said thread the call being made is as simple as </p>
  
  <pre><code> while(true){
   inputDataPool.insertDataIntoPool(inputDataPacket);
       //call some logic which comes with inputDataPacket and sleep for 2 seconds.
  }
  </code></pre>
  
  <p>and where inputDataPool.insertDataIntoPool is like</p>
  
  <pre><code>inputDataPool.insertDataIntoPool(InputDataPacket inputDataPacket){ 
   cache.get(inputDataPacket.getId());
  }
  </code></pre>
  
  <p>Now the question is, the element in cache is supposed to expire after 1000 nanosec.So when inputDataPool.insertDataIntoPool is called second time, the data which has been inserted first time will be evacuated as it must have got expired as the call is being after 2 seconds of its insertion.And then correspondingly Removal Listener should be called.
  But this is not happening. I looked into cache stats and evictionCount is always zero, no matter how much time cache.get(id) is called.</p>
  
  <p>But importantly, if I extend inputDataPool.insertDataIntoPool </p>
  
  <pre><code>  inputDataPool.insertDataIntoPool(InputDataPacket inputDataPacket){ 
   cache.get(inputDataPacket.getId());
      try{
       Thread.sleep(2000);
     }catch(InterruptedException ex){ex.printStackTrace();
       }
  cache.get(inputDataPacket.getId())
  }
  </code></pre>
  
  <p>then the eviction take place as expected with removal listener being called.</p>
  
  <p>Now I'm very much clueless at the  moment where I'm missing something to expect such kind of behaviour. Please help me see,if you see something.</p>
  
  <p>P.S. Please ignore any typos.Also no check is being made, no generic has been used, all as this is just in the phase of testing the CacheBuilder functionality.</p>
  
  <p>Thanks</p>