d5914b5703e5c23b97564eb037fc04ee431ef56e
[IRC.git] / Robust / src / ClassLibrary / MGC / gnu / ReentrantLock.java
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/licenses/publicdomain
5  */
6
7 /*package java.util.concurrent.locks;
8 import java.util.*;
9 import java.util.concurrent.*;
10 import java.util.concurrent.atomic.*;*/
11
12 /**
13  * A reentrant mutual exclusion {@link Lock} with the same basic
14  * behavior and semantics as the implicit monitor lock accessed using
15  * {@code synchronized} methods and statements, but with extended
16  * capabilities.
17  *
18  * <p>A {@code ReentrantLock} is <em>owned</em> by the thread last
19  * successfully locking, but not yet unlocking it. A thread invoking
20  * {@code lock} will return, successfully acquiring the lock, when
21  * the lock is not owned by another thread. The method will return
22  * immediately if the current thread already owns the lock. This can
23  * be checked using methods {@link #isHeldByCurrentThread}, and {@link
24  * #getHoldCount}.
25  *
26  * <p>The constructor for this class accepts an optional
27  * <em>fairness</em> parameter.  When set {@code true}, under
28  * contention, locks favor granting access to the longest-waiting
29  * thread.  Otherwise this lock does not guarantee any particular
30  * access order.  Programs using fair locks accessed by many threads
31  * may display lower overall throughput (i.e., are slower; often much
32  * slower) than those using the default setting, but have smaller
33  * variances in times to obtain locks and guarantee lack of
34  * starvation. Note however, that fairness of locks does not guarantee
35  * fairness of thread scheduling. Thus, one of many threads using a
36  * fair lock may obtain it multiple times in succession while other
37  * active threads are not progressing and not currently holding the
38  * lock.
39  * Also note that the untimed {@link #tryLock() tryLock} method does not
40  * honor the fairness setting. It will succeed if the lock
41  * is available even if other threads are waiting.
42  *
43  * <p>It is recommended practice to <em>always</em> immediately
44  * follow a call to {@code lock} with a {@code try} block, most
45  * typically in a before/after construction such as:
46  *
47  * <pre>
48  * class X {
49  *   private final ReentrantLock lock = new ReentrantLock();
50  *   // ...
51  *
52  *   public void m() {
53  *     lock.lock();  // block until condition holds
54  *     try {
55  *       // ... method body
56  *     } finally {
57  *       lock.unlock()
58  *     }
59  *   }
60  * }
61  * </pre>
62  *
63  * <p>In addition to implementing the {@link Lock} interface, this
64  * class defines methods {@code isLocked} and
65  * {@code getLockQueueLength}, as well as some associated
66  * {@code protected} access methods that may be useful for
67  * instrumentation and monitoring.
68  *
69  * <p>Serialization of this class behaves in the same way as built-in
70  * locks: a deserialized lock is in the unlocked state, regardless of
71  * its state when serialized.
72  *
73  * <p>This lock supports a maximum of 2147483647 recursive locks by
74  * the same thread. Attempts to exceed this limit result in
75  * {@link Error} throws from locking methods.
76  *
77  * @since 1.5
78  * @author Doug Lea
79  */
80 public class ReentrantLock implements /*Lock, java.io.*/Serializable {
81     private static final long serialVersionUID = 7373984872572414699L;
82     /** Synchronizer providing all implementation mechanics */
83     //private final Sync sync;
84
85     /**
86      * Base of synchronization control for this lock. Subclassed
87      * into fair and nonfair versions below. Uses AQS state to
88      * represent the number of holds on the lock.
89      */
90     /*static abstract class Sync extends AbstractQueuedSynchronizer {
91         private static final long serialVersionUID = -5179523762034025860L;
92
93         /**
94          * Performs {@link Lock#lock}. The main reason for subclassing
95          * is to allow fast path for nonfair version.
96          */
97         /*abstract void lock();
98
99         /**
100          * Performs non-fair tryLock.  tryAcquire is
101          * implemented in subclasses, but both need nonfair
102          * try for trylock method.
103          */
104         /*final boolean nonfairTryAcquire(int acquires) {
105             final Thread current = Thread.currentThread();
106             int c = getState();
107             if (c == 0) {
108                 if (compareAndSetState(0, acquires)) {
109                     setExclusiveOwnerThread(current);
110                     return true;
111                 }
112             }
113             else if (current == getExclusiveOwnerThread()) {
114                 int nextc = c + acquires;
115                 if (nextc < 0) // overflow
116                     throw new Error("Maximum lock count exceeded");
117                 setState(nextc);
118                 return true;
119             }
120             return false;
121         }
122
123         protected final boolean tryRelease(int releases) {
124             int c = getState() - releases;
125             if (Thread.currentThread() != getExclusiveOwnerThread())
126                 throw new IllegalMonitorStateException();
127             boolean free = false;
128             if (c == 0) {
129                 free = true;
130                 setExclusiveOwnerThread(null);
131             }
132             setState(c);
133             return free;
134         }
135
136         protected final boolean isHeldExclusively() {
137             // While we must in general read state before owner,
138             // we don't need to do so to check if current thread is owner
139             return getExclusiveOwnerThread() == Thread.currentThread();
140         }
141
142         final ConditionObject newCondition() {
143             return new ConditionObject();
144         }
145
146         // Methods relayed from outer class
147
148         final Thread getOwner() {
149             return getState() == 0 ? null : getExclusiveOwnerThread();
150         }
151
152         final int getHoldCount() {
153             return isHeldExclusively() ? getState() : 0;
154         }
155
156         final boolean isLocked() {
157             return getState() != 0;
158         }
159
160         /**
161          * Reconstitutes this lock instance from a stream.
162          * @param s the stream
163          */
164         /*private void readObject(java.io.ObjectInputStream s)
165             throws java.io.IOException, ClassNotFoundException {
166             s.defaultReadObject();
167             setState(0); // reset to unlocked state
168         }
169     }*/
170
171     /**
172      * Sync object for non-fair locks
173      */
174     /*final static class NonfairSync extends Sync {
175         private static final long serialVersionUID = 7316153563782823691L;
176
177         /**
178          * Performs lock.  Try immediate barge, backing up to normal
179          * acquire on failure.
180          */
181         /*final void lock() {
182             if (compareAndSetState(0, 1))
183                 setExclusiveOwnerThread(Thread.currentThread());
184             else
185                 acquire(1);
186         }
187
188         protected final boolean tryAcquire(int acquires) {
189             return nonfairTryAcquire(acquires);
190         }
191     }*/
192
193     /**
194      * Sync object for fair locks
195      */
196     /*final static class FairSync extends Sync {
197         private static final long serialVersionUID = -3000897897090466540L;
198
199         final void lock() {
200             acquire(1);
201         }
202
203         /**
204          * Fair version of tryAcquire.  Don't grant access unless
205          * recursive call or no waiters or is first.
206          */
207         /*protected final boolean tryAcquire(int acquires) {
208             final Thread current = Thread.currentThread();
209             int c = getState();
210             if (c == 0) {
211                 if (isFirst(current) &&
212                     compareAndSetState(0, acquires)) {
213                     setExclusiveOwnerThread(current);
214                     return true;
215                 }
216             }
217             else if (current == getExclusiveOwnerThread()) {
218                 int nextc = c + acquires;
219                 if (nextc < 0)
220                     throw new Error("Maximum lock count exceeded");
221                 setState(nextc);
222                 return true;
223             }
224             return false;
225         }
226     }*/
227
228     /**
229      * Creates an instance of {@code ReentrantLock}.
230      * This is equivalent to using {@code ReentrantLock(false)}.
231      */
232     public ReentrantLock() {
233         //sync = new NonfairSync();
234     }
235
236     /**
237      * Creates an instance of {@code ReentrantLock} with the
238      * given fairness policy.
239      *
240      * @param fair {@code true} if this lock should use a fair ordering policy
241      */
242     public ReentrantLock(boolean fair) {
243         //sync = (fair)? new FairSync() : new NonfairSync();
244     }
245
246     /**
247      * Acquires the lock.
248      *
249      * <p>Acquires the lock if it is not held by another thread and returns
250      * immediately, setting the lock hold count to one.
251      *
252      * <p>If the current thread already holds the lock then the hold
253      * count is incremented by one and the method returns immediately.
254      *
255      * <p>If the lock is held by another thread then the
256      * current thread becomes disabled for thread scheduling
257      * purposes and lies dormant until the lock has been acquired,
258      * at which time the lock hold count is set to one.
259      */
260     public void lock() {
261         //sync.lock();
262         System.out.println("Unimplemented ReentrantLock.lock()!");
263     }
264
265     /**
266      * Acquires the lock unless the current thread is
267      * {@linkplain Thread#interrupt interrupted}.
268      *
269      * <p>Acquires the lock if it is not held by another thread and returns
270      * immediately, setting the lock hold count to one.
271      *
272      * <p>If the current thread already holds this lock then the hold count
273      * is incremented by one and the method returns immediately.
274      *
275      * <p>If the lock is held by another thread then the
276      * current thread becomes disabled for thread scheduling
277      * purposes and lies dormant until one of two things happens:
278      *
279      * <ul>
280      *
281      * <li>The lock is acquired by the current thread; or
282      *
283      * <li>Some other thread {@linkplain Thread#interrupt interrupts} the
284      * current thread.
285      *
286      * </ul>
287      *
288      * <p>If the lock is acquired by the current thread then the lock hold
289      * count is set to one.
290      *
291      * <p>If the current thread:
292      *
293      * <ul>
294      *
295      * <li>has its interrupted status set on entry to this method; or
296      *
297      * <li>is {@linkplain Thread#interrupt interrupted} while acquiring
298      * the lock,
299      *
300      * </ul>
301      *
302      * then {@link InterruptedException} is thrown and the current thread's
303      * interrupted status is cleared.
304      *
305      * <p>In this implementation, as this method is an explicit
306      * interruption point, preference is given to responding to the
307      * interrupt over normal or reentrant acquisition of the lock.
308      *
309      * @throws InterruptedException if the current thread is interrupted
310      */
311     public void lockInterruptibly() throws InterruptedException {
312         System.out.println("Unimplemented ReentrantLock.lockInterruptibly()!");
313         //sync.acquireInterruptibly(1);
314     }
315
316     /**
317      * Acquires the lock only if it is not held by another thread at the time
318      * of invocation.
319      *
320      * <p>Acquires the lock if it is not held by another thread and
321      * returns immediately with the value {@code true}, setting the
322      * lock hold count to one. Even when this lock has been set to use a
323      * fair ordering policy, a call to {@code tryLock()} <em>will</em>
324      * immediately acquire the lock if it is available, whether or not
325      * other threads are currently waiting for the lock.
326      * This &quot;barging&quot; behavior can be useful in certain
327      * circumstances, even though it breaks fairness. If you want to honor
328      * the fairness setting for this lock, then use
329      * {@link #tryLock(long, TimeUnit) tryLock(0, TimeUnit.SECONDS) }
330      * which is almost equivalent (it also detects interruption).
331      *
332      * <p> If the current thread already holds this lock then the hold
333      * count is incremented by one and the method returns {@code true}.
334      *
335      * <p>If the lock is held by another thread then this method will return
336      * immediately with the value {@code false}.
337      *
338      * @return {@code true} if the lock was free and was acquired by the
339      *         current thread, or the lock was already held by the current
340      *         thread; and {@code false} otherwise
341      */
342     /*public boolean tryLock() {
343         return sync.nonfairTryAcquire(1);
344     }*/
345
346     /**
347      * Acquires the lock if it is not held by another thread within the given
348      * waiting time and the current thread has not been
349      * {@linkplain Thread#interrupt interrupted}.
350      *
351      * <p>Acquires the lock if it is not held by another thread and returns
352      * immediately with the value {@code true}, setting the lock hold count
353      * to one. If this lock has been set to use a fair ordering policy then
354      * an available lock <em>will not</em> be acquired if any other threads
355      * are waiting for the lock. This is in contrast to the {@link #tryLock()}
356      * method. If you want a timed {@code tryLock} that does permit barging on
357      * a fair lock then combine the timed and un-timed forms together:
358      *
359      * <pre>if (lock.tryLock() || lock.tryLock(timeout, unit) ) { ... }
360      * </pre>
361      *
362      * <p>If the current thread
363      * already holds this lock then the hold count is incremented by one and
364      * the method returns {@code true}.
365      *
366      * <p>If the lock is held by another thread then the
367      * current thread becomes disabled for thread scheduling
368      * purposes and lies dormant until one of three things happens:
369      *
370      * <ul>
371      *
372      * <li>The lock is acquired by the current thread; or
373      *
374      * <li>Some other thread {@linkplain Thread#interrupt interrupts}
375      * the current thread; or
376      *
377      * <li>The specified waiting time elapses
378      *
379      * </ul>
380      *
381      * <p>If the lock is acquired then the value {@code true} is returned and
382      * the lock hold count is set to one.
383      *
384      * <p>If the current thread:
385      *
386      * <ul>
387      *
388      * <li>has its interrupted status set on entry to this method; or
389      *
390      * <li>is {@linkplain Thread#interrupt interrupted} while
391      * acquiring the lock,
392      *
393      * </ul>
394      * then {@link InterruptedException} is thrown and the current thread's
395      * interrupted status is cleared.
396      *
397      * <p>If the specified waiting time elapses then the value {@code false}
398      * is returned.  If the time is less than or equal to zero, the method
399      * will not wait at all.
400      *
401      * <p>In this implementation, as this method is an explicit
402      * interruption point, preference is given to responding to the
403      * interrupt over normal or reentrant acquisition of the lock, and
404      * over reporting the elapse of the waiting time.
405      *
406      * @param timeout the time to wait for the lock
407      * @param unit the time unit of the timeout argument
408      * @return {@code true} if the lock was free and was acquired by the
409      *         current thread, or the lock was already held by the current
410      *         thread; and {@code false} if the waiting time elapsed before
411      *         the lock could be acquired
412      * @throws InterruptedException if the current thread is interrupted
413      * @throws NullPointerException if the time unit is null
414      *
415      */
416     /*public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException {
417         return sync.tryAcquireNanos(1, unit.toNanos(timeout));
418     }*/
419
420     /**
421      * Attempts to release this lock.
422      *
423      * <p>If the current thread is the holder of this lock then the hold
424      * count is decremented.  If the hold count is now zero then the lock
425      * is released.  If the current thread is not the holder of this
426      * lock then {@link IllegalMonitorStateException} is thrown.
427      *
428      * @throws IllegalMonitorStateException if the current thread does not
429      *         hold this lock
430      */
431     public void unlock() {
432         //sync.release(1);
433         System.out.println("Unimplemented ReentrantLock.unlock()!");
434     }
435
436     /**
437      * Returns a {@link Condition} instance for use with this
438      * {@link Lock} instance.
439      *
440      * <p>The returned {@link Condition} instance supports the same
441      * usages as do the {@link Object} monitor methods ({@link
442      * Object#wait() wait}, {@link Object#notify notify}, and {@link
443      * Object#notifyAll notifyAll}) when used with the built-in
444      * monitor lock.
445      *
446      * <ul>
447      *
448      * <li>If this lock is not held when any of the {@link Condition}
449      * {@linkplain Condition#await() waiting} or {@linkplain
450      * Condition#signal signalling} methods are called, then an {@link
451      * IllegalMonitorStateException} is thrown.
452      *
453      * <li>When the condition {@linkplain Condition#await() waiting}
454      * methods are called the lock is released and, before they
455      * return, the lock is reacquired and the lock hold count restored
456      * to what it was when the method was called.
457      *
458      * <li>If a thread is {@linkplain Thread#interrupt interrupted}
459      * while waiting then the wait will terminate, an {@link
460      * InterruptedException} will be thrown, and the thread's
461      * interrupted status will be cleared.
462      *
463      * <li> Waiting threads are signalled in FIFO order.
464      *
465      * <li>The ordering of lock reacquisition for threads returning
466      * from waiting methods is the same as for threads initially
467      * acquiring the lock, which is in the default case not specified,
468      * but for <em>fair</em> locks favors those threads that have been
469      * waiting the longest.
470      *
471      * </ul>
472      *
473      * @return the Condition object
474      */
475     public Condition newCondition() {
476       System.out.println("Unimplemented ReentrantLock.newCondition()!");
477       return null;
478         //return sync.newCondition();
479     }
480
481     /**
482      * Queries the number of holds on this lock by the current thread.
483      *
484      * <p>A thread has a hold on a lock for each lock action that is not
485      * matched by an unlock action.
486      *
487      * <p>The hold count information is typically only used for testing and
488      * debugging purposes. For example, if a certain section of code should
489      * not be entered with the lock already held then we can assert that
490      * fact:
491      *
492      * <pre>
493      * class X {
494      *   ReentrantLock lock = new ReentrantLock();
495      *   // ...
496      *   public void m() {
497      *     assert lock.getHoldCount() == 0;
498      *     lock.lock();
499      *     try {
500      *       // ... method body
501      *     } finally {
502      *       lock.unlock();
503      *     }
504      *   }
505      * }
506      * </pre>
507      *
508      * @return the number of holds on this lock by the current thread,
509      *         or zero if this lock is not held by the current thread
510      */
511     /*public int getHoldCount() {
512         return sync.getHoldCount();
513     }*/
514
515     /**
516      * Queries if this lock is held by the current thread.
517      *
518      * <p>Analogous to the {@link Thread#holdsLock} method for built-in
519      * monitor locks, this method is typically used for debugging and
520      * testing. For example, a method that should only be called while
521      * a lock is held can assert that this is the case:
522      *
523      * <pre>
524      * class X {
525      *   ReentrantLock lock = new ReentrantLock();
526      *   // ...
527      *
528      *   public void m() {
529      *       assert lock.isHeldByCurrentThread();
530      *       // ... method body
531      *   }
532      * }
533      * </pre>
534      *
535      * <p>It can also be used to ensure that a reentrant lock is used
536      * in a non-reentrant manner, for example:
537      *
538      * <pre>
539      * class X {
540      *   ReentrantLock lock = new ReentrantLock();
541      *   // ...
542      *
543      *   public void m() {
544      *       assert !lock.isHeldByCurrentThread();
545      *       lock.lock();
546      *       try {
547      *           // ... method body
548      *       } finally {
549      *           lock.unlock();
550      *       }
551      *   }
552      * }
553      * </pre>
554      *
555      * @return {@code true} if current thread holds this lock and
556      *         {@code false} otherwise
557      */
558     /*public boolean isHeldByCurrentThread() {
559         return sync.isHeldExclusively();
560     }*/
561
562     /**
563      * Queries if this lock is held by any thread. This method is
564      * designed for use in monitoring of the system state,
565      * not for synchronization control.
566      *
567      * @return {@code true} if any thread holds this lock and
568      *         {@code false} otherwise
569      */
570     /*public boolean isLocked() {
571         return sync.isLocked();
572     }*/
573
574     /**
575      * Returns {@code true} if this lock has fairness set true.
576      *
577      * @return {@code true} if this lock has fairness set true
578      */
579     /*public final boolean isFair() {
580         return sync instanceof FairSync;
581     }*/
582
583     /**
584      * Returns the thread that currently owns this lock, or
585      * {@code null} if not owned. When this method is called by a
586      * thread that is not the owner, the return value reflects a
587      * best-effort approximation of current lock status. For example,
588      * the owner may be momentarily {@code null} even if there are
589      * threads trying to acquire the lock but have not yet done so.
590      * This method is designed to facilitate construction of
591      * subclasses that provide more extensive lock monitoring
592      * facilities.
593      *
594      * @return the owner, or {@code null} if not owned
595      */
596     /*protected Thread getOwner() {
597         return sync.getOwner();
598     }*/
599
600     /**
601      * Queries whether any threads are waiting to acquire this lock. Note that
602      * because cancellations may occur at any time, a {@code true}
603      * return does not guarantee that any other thread will ever
604      * acquire this lock.  This method is designed primarily for use in
605      * monitoring of the system state.
606      *
607      * @return {@code true} if there may be other threads waiting to
608      *         acquire the lock
609      */
610     /*public final boolean hasQueuedThreads() {
611         return sync.hasQueuedThreads();
612     }*/
613
614
615     /**
616      * Queries whether the given thread is waiting to acquire this
617      * lock. Note that because cancellations may occur at any time, a
618      * {@code true} return does not guarantee that this thread
619      * will ever acquire this lock.  This method is designed primarily for use
620      * in monitoring of the system state.
621      *
622      * @param thread the thread
623      * @return {@code true} if the given thread is queued waiting for this lock
624      * @throws NullPointerException if the thread is null
625      */
626     /*public final boolean hasQueuedThread(Thread thread) {
627         return sync.isQueued(thread);
628     }*/
629
630
631     /**
632      * Returns an estimate of the number of threads waiting to
633      * acquire this lock.  The value is only an estimate because the number of
634      * threads may change dynamically while this method traverses
635      * internal data structures.  This method is designed for use in
636      * monitoring of the system state, not for synchronization
637      * control.
638      *
639      * @return the estimated number of threads waiting for this lock
640      */
641     /*public final int getQueueLength() {
642         return sync.getQueueLength();
643     }*/
644
645     /**
646      * Returns a collection containing threads that may be waiting to
647      * acquire this lock.  Because the actual set of threads may change
648      * dynamically while constructing this result, the returned
649      * collection is only a best-effort estimate.  The elements of the
650      * returned collection are in no particular order.  This method is
651      * designed to facilitate construction of subclasses that provide
652      * more extensive monitoring facilities.
653      *
654      * @return the collection of threads
655      */
656     /*protected Collection<Thread> getQueuedThreads() {
657         return sync.getQueuedThreads();
658     }*/
659
660     /**
661      * Queries whether any threads are waiting on the given condition
662      * associated with this lock. Note that because timeouts and
663      * interrupts may occur at any time, a {@code true} return does
664      * not guarantee that a future {@code signal} will awaken any
665      * threads.  This method is designed primarily for use in
666      * monitoring of the system state.
667      *
668      * @param condition the condition
669      * @return {@code true} if there are any waiting threads
670      * @throws IllegalMonitorStateException if this lock is not held
671      * @throws IllegalArgumentException if the given condition is
672      *         not associated with this lock
673      * @throws NullPointerException if the condition is null
674      */
675     /*public boolean hasWaiters(Condition condition) {
676         if (condition == null)
677             throw new NullPointerException();
678         if (!(condition instanceof AbstractQueuedSynchronizer.ConditionObject))
679             throw new IllegalArgumentException("not owner");
680         return sync.hasWaiters((AbstractQueuedSynchronizer.ConditionObject)condition);
681     }*/
682
683     /**
684      * Returns an estimate of the number of threads waiting on the
685      * given condition associated with this lock. Note that because
686      * timeouts and interrupts may occur at any time, the estimate
687      * serves only as an upper bound on the actual number of waiters.
688      * This method is designed for use in monitoring of the system
689      * state, not for synchronization control.
690      *
691      * @param condition the condition
692      * @return the estimated number of waiting threads
693      * @throws IllegalMonitorStateException if this lock is not held
694      * @throws IllegalArgumentException if the given condition is
695      *         not associated with this lock
696      * @throws NullPointerException if the condition is null
697      */
698     /*public int getWaitQueueLength(Condition condition) {
699         if (condition == null)
700             throw new NullPointerException();
701         if (!(condition instanceof AbstractQueuedSynchronizer.ConditionObject))
702             throw new IllegalArgumentException("not owner");
703         return sync.getWaitQueueLength((AbstractQueuedSynchronizer.ConditionObject)condition);
704     }*/
705
706     /**
707      * Returns a collection containing those threads that may be
708      * waiting on the given condition associated with this lock.
709      * Because the actual set of threads may change dynamically while
710      * constructing this result, the returned collection is only a
711      * best-effort estimate. The elements of the returned collection
712      * are in no particular order.  This method is designed to
713      * facilitate construction of subclasses that provide more
714      * extensive condition monitoring facilities.
715      *
716      * @param condition the condition
717      * @return the collection of threads
718      * @throws IllegalMonitorStateException if this lock is not held
719      * @throws IllegalArgumentException if the given condition is
720      *         not associated with this lock
721      * @throws NullPointerException if the condition is null
722      */
723     /*protected Collection<Thread> getWaitingThreads(Condition condition) {
724         if (condition == null)
725             throw new NullPointerException();
726         if (!(condition instanceof AbstractQueuedSynchronizer.ConditionObject))
727             throw new IllegalArgumentException("not owner");
728         return sync.getWaitingThreads((AbstractQueuedSynchronizer.ConditionObject)condition);
729     }*/
730
731     /**
732      * Returns a string identifying this lock, as well as its lock state.
733      * The state, in brackets, includes either the String {@code "Unlocked"}
734      * or the String {@code "Locked by"} followed by the
735      * {@linkplain Thread#getName name} of the owning thread.
736      *
737      * @return a string identifying this lock, as well as its lock state
738      */
739     /*public String toString() {
740         Thread o = sync.getOwner();
741         return super.toString() + ((o == null) ?
742                                    "[Unlocked]" :
743                                    "[Locked by thread " + o.getName() + "]");
744     }*/
745 }