org.apache.commons.pool
インタフェース ObjectPool

既知の実装クラスの一覧:
BaseObjectPool, GenericObjectPool, SoftReferenceObjectPool, StackObjectPool

public interface ObjectPool

プーリングを行うためのためのインターフェイスです。

A pooling interface.

ObjectPool は一般的でシンプルなプーリングインターフェイスを定義します。 必須となるメソッドは borrowObjectreturnObject だけです。

ObjectPool defines a trivially simple pooling interface. The only required methods are {@link #borrowObject borrowObject} and {@link #returnObject returnObject}.

以下に使用方法を示します:

Example of use:
 Object obj = null;

 try {
    obj = pool.borrowObject();
    //...オブジェクトを使用...
    //...use the object...

 } catch(Exception e) {
    //...例外をハンドル...
    //...handle any exceptions...

 } finally {
    // 確実にオブジェクトをプールに返す 
    // make sure the object is returned to the pool 

    if(null != obj) {
       pool.returnObject(obj);
    }
 }

シンプルな規定クラス BaseObjectPool を併せて参照ください。
See {@link org.apache.commons.pool.BaseObjectPool BaseObjectPool} for a simple base implementation.

バージョン:
$Revision: 1.1.1.1 $ $Date: 2004/02/13 10:02:01 $
作成者:
Rodney Waldhoff
翻訳者:
日置 聡
翻訳状況:
初稿(校正者募集中)
翻訳更新日:
2003/08/19

メソッドの概要
 Object borrowObject()
          プールからインスタンスを取り出します。
 void clear()
          プール内にある使用されていないオブジェクトを削除し、関連するリソースを開放します(オプショナルな処理)。
 void close()
          このプールを閉じ、関連する全てのリソースを開放します。
 int getNumActive()
          現在プールから貸し出されているインスタンスの数を返します(オプショナルな処理)。
 int getNumIdle()
          現在プール内にある使用されていないインスタンスの数を返します(オプショナルな処理)。
 void returnObject(Object obj)
          プールにインスタンスを返します。
 void setFactory(PoolableObjectFactory factory)
          新たなインスタンスを生成するために使用する factory を設定します(オプショナルな処理)。
 

メソッドの詳細

borrowObject

public Object borrowObject()
                    throws Exception
プールからインスタンスを取り出します。 プールからインスタンスを取得したクライアントは必ず returnObject または実装クラスやサブインターフェイスのそれと関連するメソッドを使用して インスタンスをプールに返さなくてはなりません。
Obtain an instance from my pool. By contract, clients MUST return the borrowed instance using {@link #returnObject(java.lang.Object) returnObject} or a related method as defined in an implementation or sub-interface.

プール内のインスタンスが空の場合のこのメソッドの振る舞いは明示されません (各実装クラスで明示されるでしょう)。

The behaviour of this method when the pool has been exhausted is not specified (although it may be specified by implementations).

戻り値:
プールから取り出されたインスタンス
an instance from my pool.
例外:
Exception

clear

public void clear()
           throws Exception,
                  UnsupportedOperationException
プール内にある使用されていないオブジェクトを削除し、関連するリソースを開放します(オプショナルな処理)。
Clears any objects sitting idle in the pool, releasing any associated resources (optional operation).

例外:
UnsupportedOperationException - この実装がこの処理をサポートしない場合
if this implementation does not support the operation
Exception

close

public void close()
           throws Exception
このプールを閉じ、関連する全てのリソースを開放します。
Close this pool, and free any resources associated with it.

例外:
Exception

getNumActive

public int getNumActive()
                 throws UnsupportedOperationException
現在プールから貸し出されているインスタンスの数を返します(オプショナルな処理)。
Return the number of instances currently borrowed from my pool (optional operation).

戻り値:
現在プールから貸し出されているインスタンスの数
the number of instances currently borrowed in my pool
例外:
UnsupportedOperationException - この実装がこの処理をサポートしない場合
if this implementation does not support the operation

getNumIdle

public int getNumIdle()
               throws UnsupportedOperationException
現在プール内にある使用されていないインスタンスの数を返します(オプショナルな処理)。 これは新たなインスタンスを生成せずに 取得 することのできるオブジェクトの数を対象とします。
Return the number of instances currently idle in my pool (optional operation). This may be considered an approximation of the number of objects that can be {@link #borrowObject borrowed} without creating any new instances.

戻り値:
プール内にある使用されていないインスタンスの数
the number of instances currently idle in my pool
例外:
UnsupportedOperationException - この実装がこの処理をサポートしない場合
if this implementation does not support the operation

returnObject

public void returnObject(Object obj)
                  throws Exception
プールにインスタンスを返します。 プールに返される obj は必ず borrowObject または実装クラスやサブインターフェイスのそれと関連するメソッドを使用して 取得されたインスタンスでなくてはなりません。
Return an instance to my pool. By contract, obj MUST have been obtained using {@link #borrowObject() borrowObject} or a related method as defined in an implementation or sub-interface.

パラメータ:
obj - プールに返す borrowObject() にて取得されたインスタンス
a {@link #borrowObject() borrowed} instance to be returned.
例外:
Exception

setFactory

public void setFactory(PoolableObjectFactory factory)
                throws IllegalStateException,
                       UnsupportedOperationException
新たなインスタンスを生成するために使用する factory を設定します(オプショナルな処理)。
Sets the {@link PoolableObjectFactory ファクトリ} I use to create new instances (optional operation).

パラメータ:
factory - 新たなインスタンスを生成するために使用する PoolableObjectFactory
the {@link PoolableObjectFactory} I use to create new instances.
例外:
IllegalStateException - ファクトリを設定できる状態でない場合
IllegalStateException when the factory cannot be set at this time
UnsupportedOperationException - この実装がこの処理をサポートしない場合
if this implementation does not support the operation


このドキュメントは、Ja-Jakartaにより訳されました。 コメントがある場合は report@jajakarta.orgまでお願いします。
Translated into Japanese by jajakarta.org. The original page is here.
Copyright (c) 2002-2003 - Apache Software Foundation