Code example for AtomicInteger

Methods: addAndGet, get

0
    return maxPoolSize;
  } 
 
  @Override 
  public int getActivePoolSize() { 
    return active.get();
  } 
 
  /** 
   * Sets the core and max size for the pool.  Core size must be >= 0 and < max. 
   * <p/> 
   * This method is NOT thread safe. 
   * 
   * @param corePoolSize min size of the pool 
   * @param maxPoolSize  max size of the pool 
   */ 
  protected final void setPoolSizes(final int corePoolSize, final int maxPoolSize) {
    Preconditions.checkArgument( 
        corePoolSize >= 0
            && maxPoolSize > 0
            && maxPoolSize >= corePoolSize
    ); 
 
    this.corePoolSize = corePoolSize;
    this.maxPoolSize = maxPoolSize;
  } 
 
  /** 
   * Attempts to expand the pool by one. 
   * 
   * @return if pool was expanded 
   */ 
  protected final boolean expand() { 
    boolean added = false;
    if (getActivePoolSize() < getMaxPoolSize()) { 
      // there is room to expand, so lets create and add an object 
      added = createAndAdd();
      if (added) {
        active.incrementAndGet();
      } 
    } 
    return added;
  } 
 
  /** 
   * Attempts to shrink the pool to corePoolSize. 
   * 
   * @return if pool shrunk.  If shrinking still left the pool larger than core, true should be returned 
   */ 
  protected final boolean shrink() { 
    final int shrinkBy = getActivePoolSize() - getCorePoolSize();
    // only shrink if active count is larger than core size 
    int removed = 0;
    if (shrinkBy > 0) {
      removed = shrink(shrinkBy);
      active.addAndGet(0 - removed); // removed should always be 0 or positive
    } 
    return removed > 0;
  } 
 
  /**