FileDocCategorySizeDatePackage
ObjectReturner.javaAPI DocExample1195Thu Nov 08 00:22:36 GMT 2001com.ora.rmibook.chapter12.pool.finalthread

ObjectReturner

public class ObjectReturner extends Object implements Runnable

Fields Summary
private Vector
_objectsToReturn
private ThreadedPool_Final
_owner
Constructors Summary
public ObjectReturner(ThreadedPool_Final owner)

        _owner = owner;
        _objectsToReturn = new Vector();
    
Methods Summary
public voidrun()

        while (true) {
            Object objectToReturn;

            while (0 == _objectsToReturn.size()) {
                synchronized (_objectsToReturn) {
                    try {
                        _objectsToReturn.wait();
                    } catch (InterruptedException e) {
                    }
                }
            }
            int lastIndex = _objectsToReturn.size() - 1;

            objectToReturn = _objectsToReturn.remove(lastIndex);
            _owner.returnObjectToPool(objectToReturn);
        }
    
public voidvalidateAndReturn(java.lang.Object object)

        synchronized (_objectsToReturn) {
            _objectsToReturn.add(object);
            if (1 == _objectsToReturn.size()) {
                _objectsToReturn.notify();
            }
        }