Java Thread Lock runSync(final Lock lock, final Runnable task)

Here you can find the source of runSync(final Lock lock, final Runnable task)

Description

Run task synchronously on current thread using provided lock for synchronization.

License

Open Source License

Parameter

Parameter Description
lock lock to be used for synchronization
task task to run

Declaration

static final void runSync(final Lock lock, final Runnable task) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.concurrent.locks.Lock;

public class Main {
    /**/*from   w w w .  ja  v a 2  s. com*/
     * Run task synchronously on current thread using provided {@code lock} for synchronization.
     * <p><b>PRE-conditions:</b> non-null {@code lock}, non-null {@code task}
     * <br><b>POST-conditions:</b> NONE
     * <br><b>Side-effects:</b> task is run on current thread
     * <br><b>Created on:</b> <i>12:34:07 PM Mar 28, 2017</i>
     * 
     * @param lock
     *            lock to be used for synchronization
     * @param task
     *            task to run
     */
    static final void runSync(final Lock lock, final Runnable task) {
        try {
            lock.lock();
            task.run();
        } finally {
            lock.unlock();
        }
    }
}

Related

  1. lockedSleep(Lock l, long time)
  2. newLinkedBlockingDeque(Collection collection)
  3. release()
  4. releaseLock(final Lock lock)
  5. releaseReadLock(final ReadWriteLock lock)
  6. sleepNanos(long nanos)
  7. sleepRandomNanos(Random random, long maxDelayNanos)