AbstractQueuedSynchronizer

Posted by sunshine on 2020-12-15
Words 270 and Reading Time 1 Minutes
Viewed Times
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package java.util.concurrent.locks;

/**
* 可能被一个线程独占的同步器, 这个类提供创建可能需要所有概念的锁和同步器的基础。
* AbstractOwnableSynchronizer 类自身并不管理或者使用这个信息。 i
* 不管怎样,子类或者工具类可能适当的维护一个值,有助于控制和监视访问并提供诊断
*
* @since 1.6
* @author Doug Lea
*/
public abstract class AbstractOwnableSynchronizer
implements java.io.Serializable {

/** Use serial ID even though all fields transient. */
private static final long serialVersionUID = 3737899427754241961L;

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

/**
* 独占同步模式下当前的持有锁的线程线程
*/
private transient Thread exclusiveOwnerThread;

/**
* 设置当前独占访问的线程,参数为null代表没有线程可以独占访问。
* This method does not otherwise impose any synchronization or
* volatile field accesses.
* @param thread the owner thread
*/
protected final void setExclusiveOwnerThread(Thread thread) {
exclusiveOwnerThread = thread;
}

/**
* 返回最新的通过setExclusiveOwnerThread方法设置的的线程,或者在从未设置过的情况下返回null
* This method does not otherwise impose any synchronization or volatile field accesses.
* @return the owner thread
*/
protected final Thread getExclusiveOwnerThread() {
return exclusiveOwnerThread;
}
}

This is copyright.