Java ReentrantLock runUnderLock(ReentrantLock lock, Runnable runnable)

Here you can find the source of runUnderLock(ReentrantLock lock, Runnable runnable)

Description

Run given runnable under given lock

License

Open Source License

Declaration

public static void runUnderLock(ReentrantLock lock, Runnable runnable) 

Method Source Code

//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();
        }
    }
}

Related

  1. isRepair()
  2. lock()
  3. readSyncLock(String id)
  4. removeJavaStdLoggerHandlers()
  5. runConcurrent(long startGapTime, Runnable... tasks)
  6. toLazyCollection(Stream stream)
  7. xor(byte[] a, byte[] b)