### Question:
Blockers { public static void enterMonitor(Monitor m) throws InterruptedException { ForkJoinPool.managedBlock(new MonitorBlocker(m)); }  static void enterMonitor(Monitor m); static void acquireSemaphore(Semaphore s);  }### Answer:
@Test public void testAcquireMonitor() { Monitor monitor = new Monitor(); ForkJoinPool.commonPool().invoke(new RecursiveAction() { AtomicInteger running = new AtomicInteger(); @Override protected void compute() { List<RecursiveAction> actions = new ArrayList<>(); for (int i = 0; i < 6; i++) { actions.add(new RecursiveAction() { @Override protected void compute() { try { Blockers.enterMonitor(monitor); try { assertThat(monitor.isOccupiedByCurrentThread(), equalTo(true)); int n = running.incrementAndGet(); assertThat(n, equalTo(1)); Thread.sleep(100); running.decrementAndGet(); } finally { monitor.leave(); } } catch (InterruptedException e) { throw new RuntimeException(e); } } }); } invokeAll(actions); for (RecursiveAction action: actions) { action.join(); } } }); }