This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
FYI: Thread.holdsLock() test case
- From: Bryce McKinlay <mckinlay at redhat dot com>
- To: java-patches at gcc dot gnu dot org
- Date: Tue, 27 Jul 2004 18:05:54 -0400
- Subject: FYI: Thread.holdsLock() test case
2004-07-27 Bryce McKinlay <mckinlay@redhat.com>
* testsuite/libjava.lang/Thread_HoldsLock.java: New test case.
* testsuite/libjava.lang/Thread_HoldsLock.out: New.
Index: testsuite/libjava.lang/Thread_HoldsLock.java
===================================================================
RCS file: testsuite/libjava.lang/Thread_HoldsLock.java
diff -N testsuite/libjava.lang/Thread_HoldsLock.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/libjava.lang/Thread_HoldsLock.java 27 Jul 2004 22:04:25 -0000
@@ -0,0 +1,27 @@
+// Test that Thread.holdsLock() works.
+
+class Lock {}
+
+public class Thread_HoldsLock
+{
+ static Lock lock = new Lock();
+
+ public static void main(String args[]) throws InterruptedException
+ {
+ Thread_HoldsLock thl = new Thread_HoldsLock();
+
+ thl.check();
+ synchronized (lock)
+ {
+ thl.check();
+ }
+ thl.check();
+ }
+
+ public void check()
+ {
+ boolean held = Thread.currentThread().holdsLock(lock);
+ System.out.println(held);
+ }
+}
+
Index: testsuite/libjava.lang/Thread_HoldsLock.out
===================================================================
RCS file: testsuite/libjava.lang/Thread_HoldsLock.out
diff -N testsuite/libjava.lang/Thread_HoldsLock.out
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/libjava.lang/Thread_HoldsLock.out 27 Jul 2004 22:04:25 -0000
@@ -0,0 +1,3 @@
+false
+true
+false