ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ReentrantLockTest.java
Revision: 1.12
Committed: Sat Dec 27 19:26:43 2003 UTC (20 years, 4 months ago) by dl
Branch: MAIN
Changes since 1.11: +5 -4 lines
Log Message:
Headers reference Creative Commons

File Contents

# User Rev Content
1 dl 1.1 /*
2 dl 1.12 * 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     * Other contributors include Andrew Wright, Jeffrey Hayes,
6     * Pat Fisher, Mike Judd.
7 dl 1.1 */
8    
9     import junit.framework.*;
10     import java.util.concurrent.locks.*;
11     import java.util.concurrent.*;
12 dl 1.5 import java.util.*;
13 dl 1.3 import java.io.*;
14 dl 1.1
15 dl 1.4 public class ReentrantLockTest extends JSR166TestCase {
16 dl 1.1 public static void main(String[] args) {
17     junit.textui.TestRunner.run (suite());
18     }
19     public static Test suite() {
20     return new TestSuite(ReentrantLockTest.class);
21     }
22    
23 dl 1.6 /**
24     * A runnable calling lockInterruptibly
25     */
26 dl 1.5 class InterruptibleLockRunnable implements Runnable {
27     final ReentrantLock lock;
28     InterruptibleLockRunnable(ReentrantLock l) { lock = l; }
29 dl 1.6 public void run() {
30     try {
31 dl 1.5 lock.lockInterruptibly();
32     } catch(InterruptedException success){}
33     }
34     }
35    
36 dl 1.6
37     /**
38     * A runnable calling lockInterruptibly that expects to be
39     * interrupted
40     */
41 dl 1.5 class InterruptedLockRunnable implements Runnable {
42     final ReentrantLock lock;
43     InterruptedLockRunnable(ReentrantLock l) { lock = l; }
44 dl 1.6 public void run() {
45     try {
46 dl 1.5 lock.lockInterruptibly();
47 dl 1.6 threadShouldThrow();
48 dl 1.5 } catch(InterruptedException success){}
49     }
50     }
51    
52     /**
53 dl 1.6 * Subclass to expose protected methods
54 dl 1.5 */
55 dl 1.6 static class PublicReentrantLock extends ReentrantLock {
56     PublicReentrantLock() { super(); }
57 dl 1.5 public Collection<Thread> getQueuedThreads() {
58     return super.getQueuedThreads();
59     }
60    
61     }
62    
63 dl 1.8 /**
64 dl 1.9 * Constructor sets given fairness
65     */
66     public void testConstructor() {
67     ReentrantLock rl = new ReentrantLock();
68     assertFalse(rl.isFair());
69     ReentrantLock r2 = new ReentrantLock(true);
70     assertTrue(r2.isFair());
71     }
72    
73     /**
74 dl 1.6 * locking an unlocked lock succeeds
75     */
76     public void testLock() {
77     ReentrantLock rl = new ReentrantLock();
78     rl.lock();
79     assertTrue(rl.isLocked());
80     rl.unlock();
81     }
82    
83 dl 1.8 /**
84 dl 1.6 * locking an unlocked fair lock succeeds
85     */
86     public void testFairLock() {
87     ReentrantLock rl = new ReentrantLock(true);
88     rl.lock();
89     assertTrue(rl.isLocked());
90     rl.unlock();
91     }
92    
93 dl 1.8 /**
94 dl 1.5 * Unlocking an unlocked lock throws IllegalMonitorStateException
95 dl 1.1 */
96 dl 1.6 public void testUnlock_IllegalMonitorStateException() {
97 dl 1.1 ReentrantLock rl = new ReentrantLock();
98 dl 1.6 try {
99 dl 1.1 rl.unlock();
100 dl 1.6 shouldThrow();
101 dl 1.1
102 dl 1.3 } catch(IllegalMonitorStateException success){}
103 dl 1.5 }
104 dl 1.1
105 dl 1.8 /**
106 dl 1.6 * trylock on an unlocked lock succeeds
107 dl 1.1 */
108 dl 1.6 public void testTryLock() {
109     ReentrantLock rl = new ReentrantLock();
110     assertTrue(rl.tryLock());
111     assertTrue(rl.isLocked());
112     rl.unlock();
113     }
114    
115 dl 1.1
116 dl 1.8 /**
117 dl 1.7 * getQueueLength reports number of waiting threads
118 dl 1.1 */
119 dl 1.7 public void testGetQueueLength() {
120 dl 1.5 final ReentrantLock lock = new ReentrantLock();
121     Thread t1 = new Thread(new InterruptedLockRunnable(lock));
122     Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
123     try {
124 dl 1.7 assertEquals(0, lock.getQueueLength());
125 dl 1.5 lock.lock();
126     t1.start();
127     Thread.sleep(SHORT_DELAY_MS);
128 dl 1.7 assertEquals(1, lock.getQueueLength());
129 dl 1.5 t2.start();
130     Thread.sleep(SHORT_DELAY_MS);
131 dl 1.7 assertEquals(2, lock.getQueueLength());
132 dl 1.5 t1.interrupt();
133     Thread.sleep(SHORT_DELAY_MS);
134 dl 1.7 assertEquals(1, lock.getQueueLength());
135 dl 1.5 lock.unlock();
136     Thread.sleep(SHORT_DELAY_MS);
137 dl 1.7 assertEquals(0, lock.getQueueLength());
138 dl 1.5 t1.join();
139     t2.join();
140     } catch(Exception e){
141 dl 1.6 unexpectedException();
142 dl 1.5 }
143     }
144    
145 dl 1.8 /**
146 dl 1.5 * getQueuedThreads includes waiting threads
147     */
148 dl 1.6 public void testGetQueuedThreads() {
149     final PublicReentrantLock lock = new PublicReentrantLock();
150 dl 1.5 Thread t1 = new Thread(new InterruptedLockRunnable(lock));
151     Thread t2 = new Thread(new InterruptibleLockRunnable(lock));
152     try {
153     assertTrue(lock.getQueuedThreads().isEmpty());
154     lock.lock();
155     assertTrue(lock.getQueuedThreads().isEmpty());
156     t1.start();
157     Thread.sleep(SHORT_DELAY_MS);
158     assertTrue(lock.getQueuedThreads().contains(t1));
159     t2.start();
160     Thread.sleep(SHORT_DELAY_MS);
161     assertTrue(lock.getQueuedThreads().contains(t1));
162     assertTrue(lock.getQueuedThreads().contains(t2));
163     t1.interrupt();
164     Thread.sleep(SHORT_DELAY_MS);
165     assertFalse(lock.getQueuedThreads().contains(t1));
166     assertTrue(lock.getQueuedThreads().contains(t2));
167     lock.unlock();
168     Thread.sleep(SHORT_DELAY_MS);
169     assertTrue(lock.getQueuedThreads().isEmpty());
170     t1.join();
171     t2.join();
172     } catch(Exception e){
173 dl 1.6 unexpectedException();
174 dl 1.5 }
175     }
176    
177 dl 1.1
178 dl 1.8 /**
179 dl 1.5 * timed trylock is interruptible.
180     */
181 dl 1.6 public void testInterruptedException2() {
182 dl 1.1 final ReentrantLock lock = new ReentrantLock();
183     lock.lock();
184     Thread t = new Thread(new Runnable() {
185 dl 1.6 public void run() {
186     try {
187 dl 1.4 lock.tryLock(MEDIUM_DELAY_MS,TimeUnit.MILLISECONDS);
188 dl 1.6 threadShouldThrow();
189 dl 1.3 } catch(InterruptedException success){}
190 dl 1.1 }
191     });
192 dl 1.4 try {
193     t.start();
194     t.interrupt();
195     } catch(Exception e){
196 dl 1.6 unexpectedException();
197 dl 1.4 }
198 dl 1.1 }
199    
200 dl 1.3
201 dl 1.5 /**
202     * Trylock on a locked lock fails
203     */
204 dl 1.3 public void testTryLockWhenLocked() {
205     final ReentrantLock lock = new ReentrantLock();
206     lock.lock();
207     Thread t = new Thread(new Runnable() {
208 dl 1.6 public void run() {
209 dl 1.4 threadAssertFalse(lock.tryLock());
210 dl 1.3 }
211     });
212     try {
213     t.start();
214     t.join();
215     lock.unlock();
216     } catch(Exception e){
217 dl 1.6 unexpectedException();
218 dl 1.3 }
219     }
220    
221 dl 1.5 /**
222 dl 1.6 * Timed trylock on a locked lock times out
223 dl 1.5 */
224 dl 1.6 public void testTryLock_Timeout() {
225 dl 1.3 final ReentrantLock lock = new ReentrantLock();
226     lock.lock();
227     Thread t = new Thread(new Runnable() {
228 dl 1.6 public void run() {
229 dl 1.3 try {
230 dl 1.4 threadAssertFalse(lock.tryLock(1, TimeUnit.MILLISECONDS));
231 dl 1.3 } catch (Exception ex) {
232 dl 1.6 threadUnexpectedException();
233 dl 1.3 }
234     }
235     });
236     try {
237     t.start();
238     t.join();
239     lock.unlock();
240     } catch(Exception e){
241 dl 1.6 unexpectedException();
242 dl 1.3 }
243     }
244 dl 1.1
245 dl 1.5 /**
246     * getHoldCount returns number of recursive holds
247     */
248 dl 1.1 public void testGetHoldCount() {
249     ReentrantLock lock = new ReentrantLock();
250 dl 1.6 for(int i = 1; i <= SIZE; i++) {
251 dl 1.1 lock.lock();
252     assertEquals(i,lock.getHoldCount());
253     }
254 dl 1.6 for(int i = SIZE; i > 0; i--) {
255 dl 1.1 lock.unlock();
256     assertEquals(i-1,lock.getHoldCount());
257     }
258     }
259    
260    
261 dl 1.5 /**
262     * isLocked is true when locked and false when not
263     */
264 dl 1.1 public void testIsLocked() {
265     final ReentrantLock lock = new ReentrantLock();
266     lock.lock();
267     assertTrue(lock.isLocked());
268     lock.unlock();
269     assertFalse(lock.isLocked());
270     Thread t = new Thread(new Runnable() {
271     public void run() {
272     lock.lock();
273     try {
274 dl 1.4 Thread.sleep(SMALL_DELAY_MS);
275 dl 1.1 }
276 dl 1.4 catch(Exception e) {
277 dl 1.6 threadUnexpectedException();
278 dl 1.4 }
279 dl 1.1 lock.unlock();
280     }
281     });
282 dl 1.6 try {
283 dl 1.1 t.start();
284     Thread.sleep(SHORT_DELAY_MS);
285     assertTrue(lock.isLocked());
286     t.join();
287     assertFalse(lock.isLocked());
288     } catch(Exception e){
289 dl 1.6 unexpectedException();
290 dl 1.1 }
291     }
292    
293    
294 dl 1.8 /**
295 dl 1.6 * lockInterruptibly is interruptible.
296     */
297     public void testLockInterruptibly1() {
298     final ReentrantLock lock = new ReentrantLock();
299     lock.lock();
300     Thread t = new Thread(new InterruptedLockRunnable(lock));
301     try {
302     t.start();
303     t.interrupt();
304     lock.unlock();
305     t.join();
306     } catch(Exception e){
307     unexpectedException();
308     }
309     }
310    
311 dl 1.5 /**
312     * lockInterruptibly succeeds when unlocked, else is interruptible
313     */
314 dl 1.6 public void testLockInterruptibly2() {
315 dl 1.1 final ReentrantLock lock = new ReentrantLock();
316 dl 1.3 try {
317     lock.lockInterruptibly();
318     } catch(Exception e) {
319 dl 1.6 unexpectedException();
320 dl 1.3 }
321 dl 1.5 Thread t = new Thread(new InterruptedLockRunnable(lock));
322 dl 1.3 try {
323     t.start();
324     t.interrupt();
325     assertTrue(lock.isLocked());
326     assertTrue(lock.isHeldByCurrentThread());
327     t.join();
328     } catch(Exception e){
329 dl 1.6 unexpectedException();
330 dl 1.3 }
331 dl 1.1 }
332 dl 1.2
333 dl 1.6 /**
334     * Calling await without holding lock throws IllegalMonitorStateException
335     */
336 dl 1.2 public void testAwait_IllegalMonitor() {
337     final ReentrantLock lock = new ReentrantLock();
338     final Condition c = lock.newCondition();
339     try {
340     c.await();
341 dl 1.6 shouldThrow();
342 dl 1.2 }
343     catch (IllegalMonitorStateException success) {
344     }
345     catch (Exception ex) {
346 dl 1.6 unexpectedException();
347 dl 1.2 }
348     }
349    
350 dl 1.6 /**
351     * Calling signal without holding lock throws IllegalMonitorStateException
352     */
353 dl 1.2 public void testSignal_IllegalMonitor() {
354     final ReentrantLock lock = new ReentrantLock();
355     final Condition c = lock.newCondition();
356     try {
357     c.signal();
358 dl 1.6 shouldThrow();
359 dl 1.2 }
360     catch (IllegalMonitorStateException success) {
361     }
362     catch (Exception ex) {
363 dl 1.6 unexpectedException();
364 dl 1.2 }
365     }
366    
367 dl 1.6 /**
368     * awaitNanos without a signal times out
369     */
370 dl 1.2 public void testAwaitNanos_Timeout() {
371     final ReentrantLock lock = new ReentrantLock();
372     final Condition c = lock.newCondition();
373     try {
374     lock.lock();
375     long t = c.awaitNanos(100);
376     assertTrue(t <= 0);
377     lock.unlock();
378     }
379     catch (Exception ex) {
380 dl 1.6 unexpectedException();
381 dl 1.2 }
382     }
383    
384 dl 1.6 /**
385     * timed await without a signal times out
386     */
387 dl 1.2 public void testAwait_Timeout() {
388     final ReentrantLock lock = new ReentrantLock();
389     final Condition c = lock.newCondition();
390     try {
391     lock.lock();
392 dl 1.4 assertFalse(c.await(SHORT_DELAY_MS, TimeUnit.MILLISECONDS));
393 dl 1.2 lock.unlock();
394     }
395     catch (Exception ex) {
396 dl 1.6 unexpectedException();
397 dl 1.2 }
398     }
399    
400 dl 1.6 /**
401     * awaitUntil without a signal times out
402     */
403 dl 1.2 public void testAwaitUntil_Timeout() {
404     final ReentrantLock lock = new ReentrantLock();
405     final Condition c = lock.newCondition();
406     try {
407     lock.lock();
408     java.util.Date d = new java.util.Date();
409     assertFalse(c.awaitUntil(new java.util.Date(d.getTime() + 10)));
410     lock.unlock();
411     }
412     catch (Exception ex) {
413 dl 1.6 unexpectedException();
414 dl 1.2 }
415     }
416    
417 dl 1.6 /**
418     * await returns when signalled
419     */
420 dl 1.2 public void testAwait() {
421     final ReentrantLock lock = new ReentrantLock();
422 dl 1.11 final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
423 dl 1.5 Thread t = new Thread(new Runnable() {
424     public void run() {
425     try {
426     lock.lock();
427     c.await();
428     lock.unlock();
429     }
430     catch(InterruptedException e) {
431 dl 1.6 threadUnexpectedException();
432 dl 1.5 }
433     }
434     });
435    
436     try {
437     t.start();
438     Thread.sleep(SHORT_DELAY_MS);
439     lock.lock();
440     c.signal();
441     lock.unlock();
442     t.join(SHORT_DELAY_MS);
443     assertFalse(t.isAlive());
444     }
445     catch (Exception ex) {
446 dl 1.6 unexpectedException();
447 dl 1.5 }
448     }
449    
450 dl 1.6 /**
451     * hasWaiters returns true when a thread is waiting, else false
452     */
453 dl 1.5 public void testHasWaiters() {
454     final ReentrantLock lock = new ReentrantLock();
455 dl 1.11 final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
456 dl 1.2 Thread t = new Thread(new Runnable() {
457     public void run() {
458     try {
459     lock.lock();
460 dl 1.5 threadAssertFalse(c.hasWaiters());
461     threadAssertEquals(0, c.getWaitQueueLength());
462 dl 1.2 c.await();
463     lock.unlock();
464     }
465     catch(InterruptedException e) {
466 dl 1.6 threadUnexpectedException();
467 dl 1.2 }
468     }
469     });
470    
471     try {
472     t.start();
473     Thread.sleep(SHORT_DELAY_MS);
474     lock.lock();
475 dl 1.5 assertTrue(c.hasWaiters());
476     assertEquals(1, c.getWaitQueueLength());
477 dl 1.2 c.signal();
478     lock.unlock();
479 dl 1.5 Thread.sleep(SHORT_DELAY_MS);
480     lock.lock();
481     assertFalse(c.hasWaiters());
482     assertEquals(0, c.getWaitQueueLength());
483     lock.unlock();
484 dl 1.2 t.join(SHORT_DELAY_MS);
485     assertFalse(t.isAlive());
486 dl 1.5 }
487     catch (Exception ex) {
488 dl 1.6 unexpectedException();
489 dl 1.5 }
490     }
491    
492 dl 1.6 /**
493     * getWaitQueueLength returns number of waiting threads
494     */
495 dl 1.5 public void testGetWaitQueueLength() {
496     final ReentrantLock lock = new ReentrantLock();
497 dl 1.11 final AbstractQueuedSynchronizer.ConditionObject c = lock.newCondition();
498 dl 1.5 Thread t1 = new Thread(new Runnable() {
499     public void run() {
500     try {
501     lock.lock();
502     threadAssertFalse(c.hasWaiters());
503     threadAssertEquals(0, c.getWaitQueueLength());
504     c.await();
505     lock.unlock();
506     }
507     catch(InterruptedException e) {
508 dl 1.6 threadUnexpectedException();
509 dl 1.5 }
510     }
511     });
512    
513     Thread t2 = new Thread(new Runnable() {
514     public void run() {
515     try {
516     lock.lock();
517     threadAssertTrue(c.hasWaiters());
518     threadAssertEquals(1, c.getWaitQueueLength());
519     c.await();
520     lock.unlock();
521     }
522     catch(InterruptedException e) {
523 dl 1.6 threadUnexpectedException();
524 dl 1.5 }
525     }
526     });
527    
528     try {
529     t1.start();
530     Thread.sleep(SHORT_DELAY_MS);
531     t2.start();
532     Thread.sleep(SHORT_DELAY_MS);
533     lock.lock();
534     assertTrue(c.hasWaiters());
535     assertEquals(2, c.getWaitQueueLength());
536     c.signalAll();
537     lock.unlock();
538     Thread.sleep(SHORT_DELAY_MS);
539     lock.lock();
540     assertFalse(c.hasWaiters());
541     assertEquals(0, c.getWaitQueueLength());
542     lock.unlock();
543     t1.join(SHORT_DELAY_MS);
544     t2.join(SHORT_DELAY_MS);
545     assertFalse(t1.isAlive());
546     assertFalse(t2.isAlive());
547 dl 1.2 }
548     catch (Exception ex) {
549 dl 1.6 unexpectedException();
550 dl 1.2 }
551     }
552    
553 dl 1.6 /**
554     * awaitUninterruptibly doesn't abort on interrupt
555     */
556 dl 1.2 public void testAwaitUninterruptibly() {
557     final ReentrantLock lock = new ReentrantLock();
558     final Condition c = lock.newCondition();
559     Thread t = new Thread(new Runnable() {
560     public void run() {
561     lock.lock();
562     c.awaitUninterruptibly();
563     lock.unlock();
564     }
565     });
566    
567     try {
568     t.start();
569     Thread.sleep(SHORT_DELAY_MS);
570     t.interrupt();
571     lock.lock();
572     c.signal();
573     lock.unlock();
574 dl 1.6 assert(t.isInterrupted());
575 dl 1.2 t.join(SHORT_DELAY_MS);
576     assertFalse(t.isAlive());
577     }
578     catch (Exception ex) {
579 dl 1.6 unexpectedException();
580 dl 1.2 }
581     }
582    
583 dl 1.6 /**
584     * await is interruptible
585     */
586 dl 1.2 public void testAwait_Interrupt() {
587     final ReentrantLock lock = new ReentrantLock();
588     final Condition c = lock.newCondition();
589     Thread t = new Thread(new Runnable() {
590     public void run() {
591     try {
592     lock.lock();
593     c.await();
594     lock.unlock();
595 dl 1.6 threadShouldThrow();
596 dl 1.2 }
597     catch(InterruptedException success) {
598     }
599     }
600     });
601    
602     try {
603     t.start();
604     Thread.sleep(SHORT_DELAY_MS);
605     t.interrupt();
606     t.join(SHORT_DELAY_MS);
607     assertFalse(t.isAlive());
608     }
609     catch (Exception ex) {
610 dl 1.6 unexpectedException();
611 dl 1.2 }
612     }
613    
614 dl 1.6 /**
615     * awaitNanos is interruptible
616     */
617 dl 1.2 public void testAwaitNanos_Interrupt() {
618     final ReentrantLock lock = new ReentrantLock();
619     final Condition c = lock.newCondition();
620     Thread t = new Thread(new Runnable() {
621     public void run() {
622     try {
623     lock.lock();
624     c.awaitNanos(SHORT_DELAY_MS * 2 * 1000000);
625     lock.unlock();
626 dl 1.6 threadShouldThrow();
627 dl 1.2 }
628     catch(InterruptedException success) {
629     }
630     }
631     });
632    
633     try {
634     t.start();
635     Thread.sleep(SHORT_DELAY_MS);
636     t.interrupt();
637     t.join(SHORT_DELAY_MS);
638     assertFalse(t.isAlive());
639     }
640     catch (Exception ex) {
641 dl 1.6 unexpectedException();
642 dl 1.2 }
643     }
644    
645 dl 1.6 /**
646     * awaitUntil is interruptible
647     */
648 dl 1.2 public void testAwaitUntil_Interrupt() {
649     final ReentrantLock lock = new ReentrantLock();
650     final Condition c = lock.newCondition();
651     Thread t = new Thread(new Runnable() {
652     public void run() {
653     try {
654     lock.lock();
655     java.util.Date d = new java.util.Date();
656     c.awaitUntil(new java.util.Date(d.getTime() + 10000));
657     lock.unlock();
658 dl 1.6 threadShouldThrow();
659 dl 1.2 }
660     catch(InterruptedException success) {
661     }
662     }
663     });
664    
665     try {
666     t.start();
667     Thread.sleep(SHORT_DELAY_MS);
668     t.interrupt();
669     t.join(SHORT_DELAY_MS);
670     assertFalse(t.isAlive());
671     }
672     catch (Exception ex) {
673 dl 1.6 unexpectedException();
674 dl 1.2 }
675     }
676    
677 dl 1.6 /**
678     * signalAll wakes up all threads
679     */
680 dl 1.2 public void testSignalAll() {
681     final ReentrantLock lock = new ReentrantLock();
682     final Condition c = lock.newCondition();
683     Thread t1 = new Thread(new Runnable() {
684     public void run() {
685     try {
686     lock.lock();
687     c.await();
688     lock.unlock();
689     }
690     catch(InterruptedException e) {
691 dl 1.6 threadUnexpectedException();
692 dl 1.2 }
693     }
694     });
695    
696     Thread t2 = new Thread(new Runnable() {
697     public void run() {
698     try {
699     lock.lock();
700     c.await();
701     lock.unlock();
702     }
703     catch(InterruptedException e) {
704 dl 1.6 threadUnexpectedException();
705 dl 1.2 }
706     }
707     });
708    
709     try {
710     t1.start();
711     t2.start();
712     Thread.sleep(SHORT_DELAY_MS);
713     lock.lock();
714     c.signalAll();
715     lock.unlock();
716     t1.join(SHORT_DELAY_MS);
717     t2.join(SHORT_DELAY_MS);
718     assertFalse(t1.isAlive());
719     assertFalse(t2.isAlive());
720     }
721     catch (Exception ex) {
722 dl 1.6 unexpectedException();
723 dl 1.3 }
724     }
725    
726 dl 1.6 /**
727     * A serialized lock deserializes as unlocked
728     */
729 dl 1.3 public void testSerialization() {
730     ReentrantLock l = new ReentrantLock();
731     l.lock();
732     l.unlock();
733    
734     try {
735     ByteArrayOutputStream bout = new ByteArrayOutputStream(10000);
736     ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout));
737     out.writeObject(l);
738     out.close();
739    
740     ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray());
741     ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin));
742     ReentrantLock r = (ReentrantLock) in.readObject();
743     r.lock();
744     r.unlock();
745     } catch(Exception e){
746     e.printStackTrace();
747 dl 1.6 unexpectedException();
748 dl 1.2 }
749     }
750 dl 1.1
751     }