summaryrefslogtreecommitdiffstats
path: root/libjava/testsuite/libjava.lang/Thread_HoldsLock.java
blob: 3a46466cb134baf820ad4cfd0a686866fa3e4fb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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);
  }
}

OpenPOWER on IntegriCloud