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