API翻译之AbstractOwnableSynchronizer

AbstractOwnableSynchronizer

一种同步器,可能只属于一个线程。该类为创建可能涉及所有权概念的锁和相关同步器提供了基础。AbstractOwnableSynchronizer类本身不管理或使用此信息。但是,子类和工具可以使用适当维护的值来帮助控制和监视访问并提供诊断。

public abstract class AbstractOwnableSynchronizer
    implements java.io.Serializable {

    /** 即使所有字段都是短暂的,也要使用串行ID。 */
    private static final long serialVersionUID = 3737899427754241961L;

    /**
     * 空构造函数,供子类使用。
     */
    protected AbstractOwnableSynchronizer() { }

    /**
     * 独占模式同步的当前所有者。
     */
    private transient Thread exclusiveOwnerThread;

    /**
     * 设置当前具有独占访问权的线程。
     * {@code null}参数表示没有线程拥有访问权。
     * 此方法不强制任何同步或{@code volatile}字段访问。
     * @param thread the owner thread
     */
    protected final void setExclusiveOwnerThread(Thread thread) {
        exclusiveOwnerThread = thread;
    }

    /**
     * 返回由{@code setExclusiveOwnerThread},
     * 或{@code null}(如果从未设置)设置的最后一个线程集。
     * 此方法不强制执行任何同步或{@code volatile}字段访问。
     * @return the owner thread
     */
    protected final Thread getExclusiveOwnerThread() {
        return exclusiveOwnerThread;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_34203832/article/details/87383203
今日推荐