1 *java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock* *ReentrantReadWriteLock.WriteLock*
3 public static class ReentrantReadWriteLock.WriteLock
4 extends |java.lang.Object|
5 implements |java.util.concurrent.locks.Lock|
8 |java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock_Description|
9 |java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock_Fields|
10 |java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock_Constructors|
11 |java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock_Methods|
13 ================================================================================
15 *java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock_Constructors*
16 |java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock(ReentrantReadWriteLock)|
18 *java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock_Methods*
19 |java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.lock()|Acquire the
20 |java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.lockInterruptibly()|
21 |java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.newCondition()|Ret
22 |java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.toString()|Returns
23 |java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.tryLock()|Acquires
24 |java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.tryLock(long,TimeUnit)|
25 |java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.unlock()|Attempts
27 *java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock_Description*
29 The lock returned by method
30 (|java.util.concurrent.locks.ReentrantReadWriteLock|) .
33 *java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock(ReentrantReadWriteLock)*
35 protected ReentrantReadWriteLock.WriteLock(java.util.concurrent.locks.ReentrantReadWriteLock lock)
37 Constructor for use by subclasses
39 lock - the outer lock object
41 *java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.lock()*
45 Acquire the write lock.
47 Acquires the write lock if neither the read nor write lock are held by another
48 thread and returns immediately, setting the write lock hold count to one.
50 If the current thread already holds the write lock then the hold count is
51 incremented by one and the method returns immediately.
53 If the lock is held by another thread then the current thread becomes disabled
54 for thread scheduling purposes and lies dormant until the write lock has been
55 acquired, at which time the write lock hold count is set to one.
58 *java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.lockInterruptibly()*
60 public void lockInterruptibly()
61 throws |java.lang.InterruptedException|
63 Acquires the write lock unless the current thread is
64 interrupted(|java.lang.Thread|) .
66 Acquires the write lock if neither the read nor write lock are held by another
67 thread and returns immediately, setting the write lock hold count to one.
69 If the current thread already holds this lock then the hold count is
70 incremented by one and the method returns immediately.
72 If the lock is held by another thread then the current thread becomes disabled
73 for thread scheduling purposes and lies dormant until one of two things
78 The write lock is acquired by the current thread; or
80 Some other thread interrupts(|java.lang.Thread|) the current thread.
84 If the write lock is acquired by the current thread then the lock hold count is
87 If the current thread:
91 has its interrupted status set on entry to this method; or
93 is interrupted(|java.lang.Thread|) while acquiring the write lock,
97 then (|java.lang.InterruptedException|) is thrown and the current thread's
98 interrupted status is cleared.
100 In this implementation, as this method is an explicit interruption point,
101 preference is given to responding to the interrupt over normal or reentrant
102 acquisition of the lock.
105 *java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.newCondition()*
107 public |java.util.concurrent.locks.Condition| newCondition()
109 Returns a (|java.util.concurrent.locks.Condition|) instance for use with this
110 (|java.util.concurrent.locks.Lock|) instance. The returned
111 (|java.util.concurrent.locks.Condition|) instance supports the same usages as
112 do the (|java.lang.Object|) monitor methods ( wait(|java.lang.Object|) ,
113 notify(|java.lang.Object|) , and notifyAll(|java.lang.Object|) ) when used with
114 the built-in monitor lock.
118 If this write lock is not held when any
119 (|java.util.concurrent.locks.Condition|) method is called then an
120 (|java.lang.IllegalMonitorStateException|) is thrown. (Read locks are held
121 independently of write locks, so are not checked or affected. However it is
122 essentially always an error to invoke a condition waiting method when the
123 current thread has also acquired read locks, since other threads that could
124 unblock it will not be able to acquire the write lock.)
126 When the condition waiting(|java.util.concurrent.locks.Condition|) methods are
127 called the write lock is released and, before they return, the write lock is
128 reacquired and the lock hold count restored to what it was when the method was
131 If a thread is interrupted(|java.lang.Thread|) while waiting then the wait will
132 terminate, an (|java.lang.InterruptedException|) will be thrown, and the
133 thread's interrupted status will be cleared.
135 Waiting threads are signalled in FIFO order.
137 The ordering of lock reacquisition for threads returning from waiting methods
138 is the same as for threads initially acquiring the lock, which is in the
139 default case not specified, but for fair locks favors those threads that have
140 been waiting the longest.
145 Returns: the Condition object
146 *java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.toString()*
148 public |java.lang.String| toString()
150 Returns a string identifying this lock, as well as its lock state. The state,
151 in brackets includes either the String Unlocked or the String Locked by
152 followed by the (|java.lang.Thread|) of the owning thread.
155 Returns: a string identifying this lock, as well as its lock state.
156 *java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.tryLock()*
158 public boolean tryLock()
160 Acquires the write lock only if it is not held by another thread at the time of
163 Acquires the write lock if neither the read nor write lock are held by another
164 thread and returns immediately with the value true, setting the write lock hold
165 count to one. Even when this lock has been set to use a fair ordering policy, a
166 call to tryLock() will immediately acquire the lock if it is available, whether
167 or not other threads are currently waiting for the write lock. This barging
168 behavior can be useful in certain circumstances, even though it breaks
169 fairness. If you want to honor the fairness setting for this lock, then use
170 tryLock(0, TimeUnit.SECONDS)
171 (|java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock|) which is almost
172 equivalent (it also detects interruption).
174 If the current thread already holds this lock then the hold count is
175 incremented by one and the method returns true.
177 If the lock is held by another thread then this method will return immediately
178 with the value false.
181 Returns: true if the lock was free and was acquired by the current thread, or the write
182 lock was already held by the current thread; and false otherwise.
183 *java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.tryLock(long,TimeUnit)*
185 public boolean tryLock(
187 java.util.concurrent.TimeUnit unit)
188 throws |java.lang.InterruptedException|
190 Acquires the write lock if it is not held by another thread within the given
191 waiting time and the current thread has not been
192 interrupted(|java.lang.Thread|) .
194 Acquires the write lock if neither the read nor write lock are held by another
195 thread and returns immediately with the value true, setting the write lock hold
196 count to one. If this lock has been set to use a fair ordering policy then an
197 available lock will not be acquired if any other threads are waiting for the
198 write lock. This is in contrast to the
199 (|java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock|) method. If you
200 want a timed tryLock that does permit barging on a fair lock then combine the
201 timed and un-timed forms together:
203 if (lock.tryLock() || lock.tryLock(timeout, unit) ) { ... }
205 If the current thread already holds this lock then the hold count is
206 incremented by one and the method returns true.
208 If the lock is held by another thread then the current thread becomes disabled
209 for thread scheduling purposes and lies dormant until one of three things
214 The write lock is acquired by the current thread; or
216 Some other thread interrupts(|java.lang.Thread|) the current thread; or
218 The specified waiting time elapses
222 If the write lock is acquired then the value true is returned and the write
223 lock hold count is set to one.
225 If the current thread:
229 has its interrupted status set on entry to this method; or
231 is interrupted(|java.lang.Thread|) while acquiring the write lock,
235 then (|java.lang.InterruptedException|) is thrown and the current thread's
236 interrupted status is cleared.
238 If the specified waiting time elapses then the value false is returned. If the
239 time is less than or equal to zero, the method will not wait at all.
241 In this implementation, as this method is an explicit interruption point,
242 preference is given to responding to the interrupt over normal or reentrant
243 acquisition of the lock, and over reporting the elapse of the waiting time.
245 timeout - the time to wait for the write lock
246 unit - the time unit of the timeout argument
248 Returns: true if the lock was free and was acquired by the current thread, or the write
249 lock was already held by the current thread; and false if the
250 waiting time elapsed before the lock could be acquired.
251 *java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock.unlock()*
255 Attempts to release this lock.
257 If the current thread is the holder of this lock then the hold count is
258 decremented. If the hold count is now zero then the lock is released. If the
259 current thread is not the holder of this lock then
260 (|java.lang.IllegalMonitorStateException|) is thrown.