1/* 2 * Written by Doug Lea with assistance from members of JCP JSR-166 3 * Expert Group and released to the public domain, as explained at 4 * http://creativecommons.org/publicdomain/zero/1.0/ 5 */ 6 7package java.util.concurrent.locks; 8 9/** 10 * A synchronizer that may be exclusively owned by a thread. This 11 * class provides a basis for creating locks and related synchronizers 12 * that may entail a notion of ownership. The 13 * <tt>AbstractOwnableSynchronizer</tt> class itself does not manage or 14 * use this information. However, subclasses and tools may use 15 * appropriately maintained values to help control and monitor access 16 * and provide diagnostics. 17 * 18 * @since 1.6 19 * @author Doug Lea 20 */ 21public abstract class AbstractOwnableSynchronizer 22 implements java.io.Serializable { 23 24 /** Use serial ID even though all fields transient. */ 25 private static final long serialVersionUID = 3737899427754241961L; 26 27 /** 28 * Empty constructor for use by subclasses. 29 */ 30 protected AbstractOwnableSynchronizer() { } 31 32 /** 33 * The current owner of exclusive mode synchronization. 34 */ 35 private transient Thread exclusiveOwnerThread; 36 37 /** 38 * Sets the thread that currently owns exclusive access. A 39 * <tt>null</tt> argument indicates that no thread owns access. 40 * This method does not otherwise impose any synchronization or 41 * <tt>volatile</tt> field accesses. 42 */ 43 protected final void setExclusiveOwnerThread(Thread t) { 44 exclusiveOwnerThread = t; 45 } 46 47 /** 48 * Returns the thread last set by 49 * <tt>setExclusiveOwnerThread</tt>, or <tt>null</tt> if never 50 * set. This method does not otherwise impose any synchronization 51 * or <tt>volatile</tt> field accesses. 52 * @return the owner thread 53 */ 54 protected final Thread getExclusiveOwnerThread() { 55 return exclusiveOwnerThread; 56 } 57} 58