21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* @test |
24 /* @test |
25 * @bug 5004077 8203765 |
25 * @bug 5004077 8203765 |
|
26 * @build SelectorUtils |
|
27 * @run main SelectAndClose |
26 * @summary Check blocking of select and close |
28 * @summary Check blocking of select and close |
27 */ |
29 */ |
28 |
30 |
29 import java.io.IOException; |
31 import java.io.IOException; |
30 import java.lang.management.ManagementFactory; |
|
31 import java.lang.management.MonitorInfo; |
|
32 import java.lang.management.ThreadInfo; |
|
33 import java.nio.channels.Selector; |
32 import java.nio.channels.Selector; |
34 |
33 |
35 public class SelectAndClose { |
34 public class SelectAndClose { |
36 static Selector selector; |
35 static Selector selector; |
37 static volatile boolean awakened = false; |
36 static volatile boolean awakened = false; |
38 |
|
39 private static boolean mightHoldLock(Thread t, Object lock) { |
|
40 long tid = t.getId(); |
|
41 int hash = System.identityHashCode(lock); |
|
42 ThreadInfo ti = ManagementFactory.getThreadMXBean(). |
|
43 getThreadInfo(new long[]{ tid} , true, false, 100)[0]; |
|
44 if (ti != null) { |
|
45 for (MonitorInfo mi : ti.getLockedMonitors()) { |
|
46 if (mi.getIdentityHashCode() == hash) |
|
47 return true; |
|
48 } |
|
49 } |
|
50 return false; |
|
51 } |
|
52 |
37 |
53 public static void main(String[] args) throws Exception { |
38 public static void main(String[] args) throws Exception { |
54 selector = Selector.open(); |
39 selector = Selector.open(); |
55 |
40 |
56 // Create and start a selector in a separate thread. |
41 // Create and start a selector in a separate thread. |