AQS前置:AbstractOwnableSynchronize

AbstractOwnableSynchronize 抽象独占同步器

/**
 * 可由线程独占的同步器  ,此类为可能包含独占概念的类提供了基础的创建锁和相关同步提供了基础
 * 此类自身不管理或者使用相关的信息,但是子类和工具类可以使用合适的值来帮助控制和监视访问并提供诊断*/
public abstract class AbstractOwnableSynchronizer
    implements java.io.Serializable {

    /** 即使所有的字段都是transient 也要使用 serial id */
    private static final long serialVersionUID = 3737899427754241961L;

    /**
     * 空构造器为子类使用
     */
    protected AbstractOwnableSynchronizer() { }

    /**
     * 独占模式同步的当前使用者
     */
    private transient Thread exclusiveOwnerThread;

    /**
     * 设置当前拥有独占访问权限的线程
     * null 意味着没有线程拥有访问权限
     * 此方法不会强制任何同步或者字段访问
     * @param thread the owner thread
     */
    protected final void setExclusiveOwnerThread(Thread thread) {
        exclusiveOwnerThread = thread;
    }

    /**
     * 返回最后被setExclusiveOwnerThread设置的值或者null当从未被设置时
     * 此方法不会强制任何同步或者任何(volatile)字段访问     * @return the owner thread
     */
    protected final Thread getExclusiveOwnerThread() {
        return exclusiveOwnerThread;
    }
}

 

posted @ 2019-07-15 22:24  gsanye  阅读(239)  评论(0编辑  收藏  举报