objectcreator.java

来自「RMI英文教程,从各个方面教你怎么进行RMI开发」· Java 代码 · 共 39 行

JAVA
39
字号
package com.ora.rmibook.chapter12.pool.thread2;


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


public class ObjectCreator implements Runnable {
    private ThreadedPool2 _owner;
    private boolean _requestPending;
    public ObjectCreator(ThreadedPool2 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();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?