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

ObjectCreator.java

package com.ora.rmibook.chapter12.pool.finalthread;


import com.ora.rmibook.chapter12.pool.*;


public class ObjectCreator implements Runnable {
    private ThreadedPool_Final _owner;
    private boolean _requestPending;
    public ObjectCreator(ThreadedPool_Final owner) {
        _owner = owner;
    }

    public void run() {
        boolean needToCreate = false;

        while (true) {
            synchronized (this) {
                while (!_requestPending) {
                    try {
                        wait();
                    } catch (InterruptedException e) {/* ignored */
                    }
                }
                needToCreate = _requestPending;
                _requestPending = false;
            }
            if (needToCreate) {
                _owner.createAndAddObject();
            }
        }
    }

    public synchronized void askForObject() {
        _requestPending = true;
        notify();
    }
}