📄 objectcreator.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -