关于#tomcat#的问题:一个httpProcessor对象都由唯一一个线程运行,为什么这两个方法需要添加synchronized关键字啊

synchronized void assign(Socket socket) {
    while(this.available) {
        try {
            this.wait();
        } catch (InterruptedException var3) {
        }
    }

    this.socket = socket;
    this.available = true;
    this.notifyAll();
    if (this.debug >= 1 && socket != null) {
        this.log(" An incoming request is being assigned");
    }

}

private synchronized Socket await() {
    while(!this.available) {
        try {
            this.wait();
        } catch (InterruptedException var2) {
        }
    }

    Socket socket = this.socket;
    this.available = false;
    this.notifyAll();
    if (this.debug >= 1 && socket != null) {
        this.log("  The incoming request has been awaited");
    }

    return socket;
}

一个httpProcessor对象都由唯一一个线程运行,并不存在线程安全问题啊,为什么这两个方法需要添加synchronized关键字啊

wait只能在synchronized块中使用