1 // Copyright 2008 The Android Open Source Project 2 3 4 5 /** 6 * Exercise monitors. 7 */ 8 public class Monitor { 9 public static int mVal = 0; 10 subTest()11 public synchronized void subTest() { 12 Object obj = new Object(); 13 synchronized (obj) { 14 mVal++; 15 obj = null; // does NOT cause a failure on exit 16 assert(obj == null); 17 } 18 } 19 20 run()21 public static void run() { 22 System.out.println("Monitor.run"); 23 24 Object obj = null; 25 26 try { 27 synchronized (obj) { 28 mVal++; 29 } 30 assert(false); 31 } catch (NullPointerException npe) { 32 /* expected */ 33 } 34 35 obj = new Object(); 36 synchronized (obj) { 37 mVal++; 38 } 39 40 new Monitor().subTest(); 41 42 assert(mVal == 2); 43 } 44 } 45 46