Here you can find the source of runUnderLock(ReentrantLock lock, Runnable runnable)
public static void runUnderLock(ReentrantLock lock, Runnable runnable)
//package com.java2s; /******************************************************************************* * Copyright (c) 2016 Bruno Medeiros and other Contributors. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w w w . j a va2s. co m*/ * Bruno Medeiros - initial API and implementation *******************************************************************************/ import java.util.concurrent.locks.ReentrantLock; public class Main { /** * Run given runnable under given lock */ public static void runUnderLock(ReentrantLock lock, Runnable runnable) { lock.lock(); try { runnable.run(); } finally { lock.unlock(); } } }