Apache Commons logo Commons Pool

CPD Results

The following document contains the results of PMD's CPD 6.29.0.

Duplications

File Line
org/apache/commons/pool2/impl/GenericKeyedObjectPool.java 1534
org/apache/commons/pool2/impl/GenericObjectPool.java 1068
final long nowMillis = System.currentTimeMillis();
            final long timeoutMillis =
                    nowMillis - abandonedConfig.getRemoveAbandonedTimeoutDuration().toMillis();
            final ArrayList<PooledObject<T>> remove = new ArrayList<>();
            final Iterator<PooledObject<T>> it = allObjects.values().iterator();
            while (it.hasNext()) {
                final PooledObject<T> pooledObject = it.next();
                synchronized (pooledObject) {
                    if (pooledObject.getState() == PooledObjectState.ALLOCATED &&
                            pooledObject.getLastUsedTime() <= timeoutMillis) {
                        pooledObject.markAbandoned();
                        remove.add(pooledObject);
                    }
                }
            }

            // Now remove the abandoned objects
            final Iterator<PooledObject<T>> itr = remove.iterator();
            while (itr.hasNext()) {
                final PooledObject<T> pooledObject = itr.next();
                if (abandonedConfig.getLogAbandoned()) {
                    pooledObject.printStackTrace(abandonedConfig.getLogWriter());
                }
                try {
                    invalidateObject(pool.getKey(), pooledObject.getObject(), DestroyMode.ABANDONED);
File Line
org/apache/commons/pool2/impl/GenericKeyedObjectPool.java 1716
org/apache/commons/pool2/impl/GenericObjectPool.java 1195
}
    /**
     * Sets the abandoned object removal configuration.
     *
     * @param abandonedConfig the new configuration to use. This is used by value.
     *
     * @see AbandonedConfig
     * @since 2.10.0
     */
    @SuppressWarnings("resource") // PrintWriter is managed elsewhere
    public void setAbandonedConfig(final AbandonedConfig abandonedConfig) {
        if (abandonedConfig == null) {
            this.abandonedConfig = null;
        } else {
            this.abandonedConfig = new AbandonedConfig();
            this.abandonedConfig.setLogAbandoned(abandonedConfig.getLogAbandoned());
            this.abandonedConfig.setLogWriter(abandonedConfig.getLogWriter());
            this.abandonedConfig.setRemoveAbandonedOnBorrow(abandonedConfig.getRemoveAbandonedOnBorrow());
            this.abandonedConfig.setRemoveAbandonedOnMaintenance(abandonedConfig.getRemoveAbandonedOnMaintenance());
            this.abandonedConfig.setRemoveAbandonedTimeout(abandonedConfig.getRemoveAbandonedTimeoutDuration());
            this.abandonedConfig.setUseUsageTracking(abandonedConfig.getUseUsageTracking());
            this.abandonedConfig.setRequireFullStackTrace(abandonedConfig.getRequireFullStackTrace());
        }
    }
    /**
     * Sets the configuration.
     *
     * @param conf the new configuration to use. This is used by value.
     *
     * @see GenericKeyedObjectPoolConfig
     */
    public void setConfig(final GenericKeyedObjectPoolConfig<T> conf) {
File Line
org/apache/commons/pool2/impl/GenericKeyedObjectPool.java 1275
org/apache/commons/pool2/impl/GenericObjectPool.java 893
}

    /**
     * Gets whether a check is made for abandoned objects when an object is borrowed
     * from this pool.
     *
     * @return {@code true} if abandoned object removal is configured to be
     *         activated by borrowObject otherwise {@code false}
     *
     * @see AbandonedConfig#getRemoveAbandonedOnBorrow()
     * @since 2.10.0
     */
    @Override
    public boolean getRemoveAbandonedOnBorrow() {
        final AbandonedConfig ac = this.abandonedConfig;
        return ac != null && ac.getRemoveAbandonedOnBorrow();
    }

    /**
     * Gets whether a check is made for abandoned objects when the evictor runs.
     *
     * @return {@code true} if abandoned object removal is configured to be
     *         activated when the evictor runs otherwise {@code false}
     *
     * @see AbandonedConfig#getRemoveAbandonedOnMaintenance()
     * @since 2.10.0
     */
    @Override
    public boolean getRemoveAbandonedOnMaintenance() {
        final AbandonedConfig ac = this.abandonedConfig;
        return ac != null && ac.getRemoveAbandonedOnMaintenance();
    }

    /**
     * Gets the timeout before which an object will be considered to be
     * abandoned by this pool.
     *
     * @return The abandoned object timeout in seconds if abandoned object
     *         removal is configured for this pool; Integer.MAX_VALUE otherwise.
     *
     * @see AbandonedConfig#getRemoveAbandonedTimeout()
     * @see AbandonedConfig#getRemoveAbandonedTimeoutDuration()
     * @deprecated Use {@link #getRemoveAbandonedTimeoutDuration()}.
     * @since 2.10.0
     */
    @Override
    @Deprecated
    public int getRemoveAbandonedTimeout() {
        final AbandonedConfig ac = this.abandonedConfig;
        return ac != null ? ac.getRemoveAbandonedTimeout() : Integer.MAX_VALUE;
    }

    /**
     * Gets the timeout before which an object will be considered to be
     * abandoned by this pool.
     *
     * @return The abandoned object timeout in seconds if abandoned object
     *         removal is configured for this pool; Integer.MAX_VALUE otherwise.
     *
     * @see AbandonedConfig#getRemoveAbandonedTimeout()
     * @see AbandonedConfig#getRemoveAbandonedTimeoutDuration()
     * @since 2.10.0
     */
    public Duration getRemoveAbandonedTimeoutDuration() {
        final AbandonedConfig ac = this.abandonedConfig;
        return ac != null ? ac.getRemoveAbandonedTimeoutDuration() : DEFAULT_REMOVE_ABANDONED_TIMEOUT;
    }