FileDocCategorySizeDatePackage
VectorPoolManager.javaAPI DocExample1510Tue Dec 22 20:14:42 GMT 1998tuning.reuse

VectorPoolManager

public class VectorPoolManager extends Object

Fields Summary
Vector[]
pool
boolean[]
inUse
Constructors Summary
public VectorPoolManager(int initialPoolSize)

    pool = new Vector[initialPoolSize];
    inUse = new boolean[initialPoolSize];
    for (int i = pool.length-1; i>=0; i--)
    {
      pool[i] = new Vector();
      inUse[i] = false;
    }
  
Methods Summary
public synchronized java.util.VectorgetVector()

    for (int i = inUse.length-1; i >= 0; i--)
      if (!inUse[i])
      {
        inUse[i] = true;
        return pool[i];
      }

    //If we got here, then all the Vectors are in use. We will increase the number in our
    //pool by 10 (arbitrary value for illustration purposes).
    boolean[] old_inUse = inUse;
    inUse = new boolean[old_inUse.length+10];
    System.arraycopy(old_inUse, 0, inUse, 0, old_inUse.length);

    Vector[] old_pool = pool;
    pool = new Vector[old_pool.length+10];
    System.arraycopy(old_pool, 0, pool, 0, old_pool.length);

    for (int i = old_pool.length; i < pool.length; i++)
    {
      pool[i] = new Vector();
      inUse[i] = false;
    }
    inUse[pool.length-1] = true;
    return pool[pool.length-1];
  
public synchronized voidreturnVector(java.util.Vector v)

    for (int i = inUse.length-1; i >= 0; i--)
      if (pool[i] == v)
      {
        inUse[i] = false;
	v.setSize(0);
        return;
      }
    throw new RuntimeException("Vector was not obtained from the pool: " + v);