Java 的 Object 类 下 wait 与 notify 方法 javadoc 翻译

    //########
    //public final void wait() throws InterruptedException
    //########
    /**
     * Causes the current thread to wait until another thread invokes the
     * {@link java.lang.Object#notify()} method or the
     * {@link java.lang.Object#notifyAll()} method for this object.
     * 促使此当前线程进入此object的等待队列,直到其他线程执行 此 object 的 notify() 或 notifyAll() 
     * 才会离开此对象的等待队列 获取CPU并竞争此object锁 
     * In other words, this method behaves exactly as if it simply
     * performs the call {@code wait(0)}.
     * 等同于 简单执行 wait(0) 这个行为   
     * <p>
     * The current thread must own this object's monitor. The thread
     * 执行wait的线程注定必须拥有此对象监视器的所有权,拥有的大前提如下:
     * releases ownership of this monitor and waits until another thread
     * '某线程释放了对象监控的所有权'  且 直到另外一个线程通知 '正在等待此对象监视器的线程们'从等待队列醒来 
     * (备注:醒来后的线程会等待CPU时间片走正常的竞争逻辑代码去争夺对象监视器)
     * notifies threads waiting on this object's monitor to wake up
     * 通知 '正在等待此对象监视器的线程们'从等待队列醒来 的方法 有 notify 与 notifyAll
     * either through a call to the {@code notify} method or the
     * {@code notifyAll} method. The thread then waits until it can
     * '正在等待此对象监视器的线程们' 只有等到 成为 对象监视器的 拥有者 时  才能 恢复执行
     * (备注:所谓恢复执行即,在哪段代码失去的CPU,就在哪段代码获取CPU和拥有对象监视器 并继续往下执行下面的代码)
     * re-obtain ownership of the monitor and resumes execution.
     * 
     * <p>
     * As in the one argument version, interrupts and spurious wakeups are
     * 在一个参数版本中 , 线程 有 中断 和 虚假唤醒 的可能
     * possible, and this method should always be used in a loop:
     * 且 此方法应该始终在一个循环中使用
     * <pre>
     *         同步代码块 约束 线程们对这段代码 同步串行  执行 
     *     synchronized (obj) {
     *         while (&lt;condition does not hold&gt;)
     *             obj.wait();
     *         ... // Perform action appropriate to condition
     *     }
     * </pre>
     * This method should only be called by a thread that is the owner
     * 这个object的wait方法只能被   '拥有这个对象监视器' 的线程执行
     * of this object's monitor. See the {@code notify} method for a
     * 
     * description of the ways in which a thread can become the owner of
     * notify 这个方法 描述了 一个线程 成为 object对象的monitor监视器 的 owner拥有者 的 实现细节
     * a monitor.
     *
     * @throws  IllegalMonitorStateException  if the current thread is not
     *               the owner of the object's monitor.
     *               如果 此当前线程 不是 该对象监视器 的 拥有者时 则 抛出 IllegalMonitorStateException 型异常
     * @throws  InterruptedException if any thread interrupted the
     *             current thread before or while the current thread
     *             was waiting for a notification.  The <i>interrupted
     *             status</i> of the current thread is cleared when
     *             this exception is thrown.
     *             如果 其他任意一个线程  对 这个当前线程发出中断信号
     *             备注: (这个收到中断信号的当前线程有可能正在该对象监视器的等待队列中等着某个线程调用对象的notify或notifyAll)
     *             当此异常被抛出时 这个线程的中断状态会被重置(即:中断信号标识会重置为非中断)
     *             #对于线程中断标识的一点科普
     *             a线程失去CPU进入资源等待队列中,b线程拥有CPU并对a线程发送了一个中断信号(此时a线程因失去cpu不能及时对这个中断信号及时作出响应,所以b线程会设置a线程的中断信号标识字段为true),
     *             a线程重获CPU后先检查自身的中断信号信号字段的值以确认自己失去CPU期间是否有其他线程中断过自己,
     *             如果有那么就抛出中断异常  InterruptedException 以响应 这个中断信号
     *             如果没有那么就在失去CPU的代码段处重获CPU并继续执行代码
     * @see        java.lang.Object#notify()
     * @see        java.lang.Object#notifyAll()
     */
    
    //########
    //public final native void notify();
    //########
    /**
     * Wakes up a single thread that is waiting on this object's
     * 唤醒 正在等待此对象监视器 的 单个线程
     * monitor. If any threads are waiting on this object, one of them
     * 如果有大于等于1个线程正在等待这个对象, 那么他们中的一个会被选择进行唤醒
     * is chosen to be awakened. The choice is arbitrary and occurs at
     * 选择的机制是任意的 且 选择的实现也是可自行决定
     * the discretion of the implementation. A thread waits on an object's
     * 一个线程调用 wait() 方法在一个对象的监视器 上 进行 等待
     * monitor by calling one of the {@code wait} methods.
     * <p>
     * The awakened thread will not be able to proceed until the current
     * 如果占据锁的当前线程没有释放这个对象上的锁,那么被唤醒的线程依然无法继续执行(即会继续等待)
     * thread relinquishes the lock on this object. The awakened thread will
     * 被唤醒的线程 使用正常方式 与 '其他活跃的线程' 以同步竞争的方式 , 竞争 这个对象的锁(或者说 锁定独占此对象)
     * compete in the usual manner with any other threads that might be
     * 
     * actively competing to synchronize on this object; for example, the
     * 举例解释: 被唤醒的进程 在将来成为下一个锁定此对象的进程的过程中 是没有 优势与劣势 
     * awakened thread enjoys no reliable privilege or disadvantage in being
     * 
     * the next thread to lock this object.
     * <p>
     * This method should only be called by a thread that is the owner
     * 此方法只会被 '此对象监视器的拥有者(即成功锁定此对象的那个线程)' 调用
     * of this object's monitor. A thread becomes the owner of the
     * 一个线程 想成为 此对象监视器的拥有者, 可通过如下的方法 来实现
     * object's monitor in one of three ways:
     * <ul>
     * <li>By executing a synchronized instance method of that object.
     *         执行此对象的一个同步实例方法
     * <li>By executing the body of a {@code synchronized} statement
     *         通过执行 synchronized 语句的执行体 在这个对象上实现 '多线程同步串行'
     *     that synchronizes on the object.
     * <li>For objects of type {@code Class,} by executing a
     *         对于类型为Class的objects, 通过执行该class的 同步-静态-方法
     *     synchronized static method of that class.
     * </ul>
     * <p>
     * Only one thread at a time can own an object's monitor.
     *    任意时刻仅有一个线程 能 成为 这个对象监控 的 拥有者
     * @throws  IllegalMonitorStateException  if the current thread is not
     *               the owner of this object's monitor.
     *               如果 此当前线程 不是 该对象监视器 的 拥有者时 则 抛出 IllegalMonitorStateException 型异常
     * @see        java.lang.Object#notifyAll()
     * @see        java.lang.Object#wait()
     */

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值