必要なのは ObjectPool です。Apache Commons Pool http://commons.apache.org/poolをチェックしてください
アプリケーションの起動時に、商用ライブラリのライセンスまたはオブジェクトを使用してオブジェクト プールを作成する必要があります (どの種類のパブリック インターフェイスがあるかはわかりません)。
public class CommercialObjectFactory extends BasePoolableObjectFactory {
// for makeObject we'll simply return a new commercial object
@Override
public Object makeObject() {
return new CommercialObject();
}
}
GenericObjectPool pool = new GenericObjectPool(new CommercialObjectFactory());
// The size of pool in our case it is N
pool.setMaxActive(N)
// We want to wait if the pool is exhausted
pool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_BLOCK)
また、コードで商用オブジェクトが必要な場合。
CommercialObject obj = null;
try {
obj = (CommercialObject)pool.borrowObject();
// use the commerical object the way you to use it.
// ....
} finally {
// be nice return the borrwed object
try {
if(obj != null) {
pool.returnObject(obj);
}
} catch(Exception e) {
// ignored
}
}
これが望まない場合は、商用ライブラリに関する詳細を提供する必要があります。