ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/LockSupportTest.java
Revision: 1.3
Committed: Sat Sep 20 18:20:08 2003 UTC (20 years, 7 months ago) by dl
Branch: MAIN
Changes since 1.2: +30 -21 lines
Log Message:
Documentation scaffolding

File Contents

# User Rev Content
1 dl 1.1 /*
2     * Written by members of JCP JSR-166 Expert Group and released to the
3     * public domain. Use, modify, and redistribute this code in any way
4     * without acknowledgement. Other contributors include Andrew Wright,
5     * Jeffrey Hayes, Pat Fischer, Mike Judd.
6     */
7    
8     import junit.framework.*;
9     import java.util.*;
10     import java.util.concurrent.*;
11     import java.util.concurrent.locks.*;
12    
13 dl 1.2 public class LockSupportTest extends JSR166TestCase{
14 dl 1.1 public static void main(String[] args) {
15     junit.textui.TestRunner.run (suite());
16     }
17     public static Test suite() {
18     return new TestSuite(LockSupportTest.class);
19     }
20    
21 dl 1.3 /**
22     *
23     */
24 dl 1.1 public void testUnpark() {
25 dl 1.3 Thread t = new Thread(new Runnable() {
26     public void run() {
27     try {
28 dl 1.1 LockSupport.park();
29 dl 1.3 } catch(Exception e){
30     threadUnexpectedException();
31 dl 1.1 }
32     }
33     });
34     t.start();
35 dl 1.3 try {
36 dl 1.1 LockSupport.unpark(t);
37     t.join();
38     }
39     catch(Exception e) {
40 dl 1.3 unexpectedException();
41 dl 1.1 }
42     }
43    
44 dl 1.3 /**
45     *
46     */
47 dl 1.1 public void testParkNanos() {
48 dl 1.3 Thread t = new Thread(new Runnable() {
49     public void run() {
50     try {
51 dl 1.1 LockSupport.parkNanos(1000);
52 dl 1.3 } catch(Exception e){
53     threadUnexpectedException();
54 dl 1.1 }
55     }
56     });
57 dl 1.3 try {
58 dl 1.1 t.start();
59     t.join();
60     }
61     catch(Exception e) {
62 dl 1.3 unexpectedException();
63 dl 1.1 }
64     }
65    
66    
67 dl 1.3 /**
68     *
69     */
70 dl 1.1 public void testParkUntil() {
71 dl 1.3 Thread t = new Thread(new Runnable() {
72     public void run() {
73     try {
74 dl 1.1 long d = new Date().getTime() + 100;
75     LockSupport.parkUntil(d);
76 dl 1.3 } catch(Exception e){
77     threadUnexpectedException();
78 dl 1.1 }
79     }
80     });
81 dl 1.3 try {
82 dl 1.1 t.start();
83     t.join();
84     }
85     catch(Exception e) {
86 dl 1.3 unexpectedException();
87 dl 1.1 }
88     }
89     }