⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genericobjectpool.java

📁 mysql集群
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * of "active" objects has been reached).     *     * @param whenExhaustedAction the action code, which must be one of     *        {@link #WHEN_EXHAUSTED_BLOCK}, {@link #WHEN_EXHAUSTED_FAIL},     *        or {@link #WHEN_EXHAUSTED_GROW}     * @see #getWhenExhaustedAction     */    public synchronized void setWhenExhaustedAction(byte whenExhaustedAction) {        switch(whenExhaustedAction) {            case WHEN_EXHAUSTED_BLOCK:            case WHEN_EXHAUSTED_FAIL:            case WHEN_EXHAUSTED_GROW:                _whenExhaustedAction = whenExhaustedAction;                notifyAll();                break;            default:                throw new IllegalArgumentException("whenExhaustedAction " + whenExhaustedAction + " not recognized.");        }    }    /**     * Returns the maximum amount of time (in milliseconds) the     * {@link #borrowObject} method should block before throwing     * an exception when the pool is exhausted and the     * {@link #setWhenExhaustedAction "when exhausted" action} is     * {@link #WHEN_EXHAUSTED_BLOCK}.     *     * When less than or equal to 0, the {@link #borrowObject} method     * may block indefinitely.     *     * @return maximum number of milliseconds to block when borrowing an object.     * @see #setMaxWait     * @see #setWhenExhaustedAction     * @see #WHEN_EXHAUSTED_BLOCK     */    public long getMaxWait() {        return _maxWait;    }    /**     * Sets the maximum amount of time (in milliseconds) the     * {@link #borrowObject} method should block before throwing     * an exception when the pool is exhausted and the     * {@link #setWhenExhaustedAction "when exhausted" action} is     * {@link #WHEN_EXHAUSTED_BLOCK}.     *     * When less than or equal to 0, the {@link #borrowObject} method     * may block indefinitely.     *     * @param maxWait maximum number of milliseconds to block when borrowing an object.     * @see #getMaxWait     * @see #setWhenExhaustedAction     * @see #WHEN_EXHAUSTED_BLOCK     */    public synchronized void setMaxWait(long maxWait) {        _maxWait = maxWait;        notifyAll();    }    /**     * Returns the cap on the number of "idle" instances in the pool.     * @return the cap on the number of "idle" instances in the pool.     * @see #setMaxIdle     */    public int getMaxIdle() {        return _maxIdle;    }    /**     * Sets the cap on the number of "idle" instances in the pool.     * @param maxIdle The cap on the number of "idle" instances in the pool.     * Use a negative value to indicate an unlimited number of idle instances.     * @see #getMaxIdle     */    public synchronized void setMaxIdle(int maxIdle) {        _maxIdle = maxIdle;        notifyAll();    }    /**     * Sets the minimum number of objects allowed in the pool     * before the evictor thread (if active) spawns new objects.     * Note that no objects are created when      * <code>numActive + numIdle >= maxActive.</code>     * This setting has no effect if the idle object evictor is disabled     * (i.e. if <code>timeBetweenEvictionRunsMillis <= 0</code>).     *     * @param minIdle The minimum number of objects.     * @see #getMinIdle     * @see #getTimeBetweenEvictionRunsMillis()     */    public synchronized void setMinIdle(int minIdle) {        _minIdle = minIdle;        notifyAll();    }    /**     * Returns the minimum number of objects allowed in the pool     * before the evictor thread (if active) spawns new objects.     * (Note no objects are created when: numActive + numIdle >= maxActive)     *     * @return The minimum number of objects.     * @see #setMinIdle     */    public int getMinIdle() {        return _minIdle;    }    /**     * When <tt>true</tt>, objects will be     * {@link PoolableObjectFactory#validateObject validated}     * before being returned by the {@link #borrowObject}     * method.  If the object fails to validate,     * it will be dropped from the pool, and we will attempt     * to borrow another.     *     * @return <code>true</code> if objects are validated before being borrowed.     * @see #setTestOnBorrow     */    public boolean getTestOnBorrow() {        return _testOnBorrow;    }    /**     * When <tt>true</tt>, objects will be     * {@link PoolableObjectFactory#validateObject validated}     * before being returned by the {@link #borrowObject}     * method.  If the object fails to validate,     * it will be dropped from the pool, and we will attempt     * to borrow another.     *     * @param testOnBorrow <code>true</code> if objects should be validated before being borrowed.     * @see #getTestOnBorrow     */    public void setTestOnBorrow(boolean testOnBorrow) {        _testOnBorrow = testOnBorrow;    }    /**     * When <tt>true</tt>, objects will be     * {@link PoolableObjectFactory#validateObject validated}     * before being returned to the pool within the     * {@link #returnObject}.     *     * @return <code>true</code> when objects will be validated after returned to {@link #returnObject}.     * @see #setTestOnReturn     */    public boolean getTestOnReturn() {        return _testOnReturn;    }    /**     * When <tt>true</tt>, objects will be     * {@link PoolableObjectFactory#validateObject validated}     * before being returned to the pool within the     * {@link #returnObject}.     *     * @param testOnReturn <code>true</code> so objects will be validated after returned to {@link #returnObject}.     * @see #getTestOnReturn     */    public void setTestOnReturn(boolean testOnReturn) {        _testOnReturn = testOnReturn;    }    /**     * Returns the number of milliseconds to sleep between runs of the     * idle object evictor thread.     * When non-positive, no idle object evictor thread will be     * run.     *     * @return number of milliseconds to sleep between evictor runs.     * @see #setTimeBetweenEvictionRunsMillis     */    public long getTimeBetweenEvictionRunsMillis() {        return _timeBetweenEvictionRunsMillis;    }    /**     * Sets the number of milliseconds to sleep between runs of the     * idle object evictor thread.     * When non-positive, no idle object evictor thread will be     * run.     *     * @param timeBetweenEvictionRunsMillis number of milliseconds to sleep between evictor runs.     * @see #getTimeBetweenEvictionRunsMillis     */    public synchronized void setTimeBetweenEvictionRunsMillis(long timeBetweenEvictionRunsMillis) {        _timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;        startEvictor(_timeBetweenEvictionRunsMillis);    }    /**     * Returns the max number of objects to examine during each run of the     * idle object evictor thread (if any).     *     * @return max number of objects to examine during each evictor run.     * @see #setNumTestsPerEvictionRun     * @see #setTimeBetweenEvictionRunsMillis     */    public int getNumTestsPerEvictionRun() {        return _numTestsPerEvictionRun;    }    /**     * Sets the max number of objects to examine during each run of the     * idle object evictor thread (if any).     * <p>     * When a negative value is supplied, <tt>ceil({@link #getNumIdle})/abs({@link #getNumTestsPerEvictionRun})</tt>     * tests will be run.  I.e., when the value is <i>-n</i>, roughly one <i>n</i>th of the     * idle objects will be tested per run.     *     * @param numTestsPerEvictionRun max number of objects to examine during each evictor run.     * @see #getNumTestsPerEvictionRun     * @see #setTimeBetweenEvictionRunsMillis     */    public void setNumTestsPerEvictionRun(int numTestsPerEvictionRun) {        _numTestsPerEvictionRun = numTestsPerEvictionRun;    }    /**     * Returns the minimum amount of time an object may sit idle in the pool     * before it is eligible for eviction by the idle object evictor     * (if any).     *     * @return minimum amount of time an object may sit idle in the pool before it is eligible for eviction.     * @see #setMinEvictableIdleTimeMillis     * @see #setTimeBetweenEvictionRunsMillis     */    public long getMinEvictableIdleTimeMillis() {        return _minEvictableIdleTimeMillis;    }    /**     * Sets the minimum amount of time an object may sit idle in the pool     * before it is eligible for eviction by the idle object evictor     * (if any).     * When non-positive, no objects will be evicted from the pool     * due to idle time alone.     * @param minEvictableIdleTimeMillis minimum amount of time an object may sit idle in the pool before it is eligible for eviction.     * @see #getMinEvictableIdleTimeMillis     * @see #setTimeBetweenEvictionRunsMillis     */    public synchronized void setMinEvictableIdleTimeMillis(long minEvictableIdleTimeMillis) {        _minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;    }    /**     * Returns the minimum amount of time an object may sit idle in the pool     * before it is eligible for eviction by the idle object evictor     * (if any), with the extra condition that at least     * "minIdle" amount of object remain in the pool.     *     * @return minimum amount of time an object may sit idle in the pool before it is eligible for eviction.     * @since Pool 1.3     * @see #setSoftMinEvictableIdleTimeMillis     */    public long getSoftMinEvictableIdleTimeMillis() {        return _softMinEvictableIdleTimeMillis;    }    /**     * Sets the minimum amount of time an object may sit idle in the pool     * before it is eligible for eviction by the idle object evictor     * (if any), with the extra condition that at least     * "minIdle" amount of object remain in the pool.     * When non-positive, no objects will be evicted from the pool     * due to idle time alone.     *     * @param softMinEvictableIdleTimeMillis minimum amount of time an object may sit idle in the pool before it is eligible for eviction.     * @since Pool 1.3     * @see #getSoftMinEvictableIdleTimeMillis     */    public synchronized void setSoftMinEvictableIdleTimeMillis(long softMinEvictableIdleTimeMillis) {        _softMinEvictableIdleTimeMillis = softMinEvictableIdleTimeMillis;    }    /**     * When <tt>true</tt>, objects will be     * {@link PoolableObjectFactory#validateObject validated}     * by the idle object evictor (if any).  If an object     * fails to validate, it will be dropped from the pool.     *     * @return <code>true</code> when objects will be validated by the evictor.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -