Java 8 ReentrantLock - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ReentrantLock class.

This code example shows how to use the following methods:lock, unlock
	private static ByteBuffer sSharedByteBuffer;
 
	public static int getSharedByteBufferByteCapacity() { 
		final int byteCapacity;
		try { 
			SharedMemoryVertexBufferObject.sSharedByteBufferLock.lock();
 
			final ByteBuffer sharedByteBuffer = SharedMemoryVertexBufferObject.sSharedByteBuffer;
			if(sharedByteBuffer == null) {
				byteCapacity = 0;
			} else { 
				byteCapacity = sharedByteBuffer.capacity();
			} 
		} finally { 
			SharedMemoryVertexBufferObject.sSharedByteBufferLock.unlock();
		} 
 
		return byteCapacity;
	} 
 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
	private volatile boolean shutdownInProgress;
 
 
	private final Lock flushLock = new ReentrantLock();
 
	private final Lock closeLock = new ReentrantLock();
 
 
	public ConcurrentWebSocketSessionDecorator(WebSocketSession delegate, int sendTimeLimit, int bufferSizeLimit) {
		super(delegate);
		this.sendTimeLimit = sendTimeLimit;
		this.bufferSizeLimit = bufferSizeLimit;
	} 
 
 
	public int getBufferSize() { 
		return this.bufferSize.get();
	} 
 
	public long getTimeSinceSendStarted() { 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isLocked, lock, unlock
package de.unisb.cs.st.javalanche.mutation.bytecodeMutations.replaceThreadCalls.classes; 
 
import java.util.concurrent.locks.ReentrantLock;
 
public class LockUnlockTEMPLATE { 
 
	int counter = 1;
 
	public boolean m1() { 
		ReentrantLock lock = new ReentrantLock();
		lock.lock(); 
		try { 
			counter++;
		} finally { 
			lock.unlock();
		} 
		return lock.isLocked();
	} 
} 

9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:lock, unlock
        return offer(t);
    } 
 
    @Override 
    public boolean offer(T t) {
        lock.lock();
        try { 
            elements.add(t);
            notEmpty.signal();
            return true; 
        } finally { 
            lock.unlock();
        } 
    } 
 
    @Override 
    public T poll() { 
        lock.lock();
        try { 
            return dequeue(); 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
/** 
 * A MavenPublisher that restricts publishing to a single thread per Classloader that loads this class. 
 * This is required to prevent concurrent access to the Maven Ant Tasks, which hold static state. 
 */ 
public class StaticLockingMavenPublisher implements MavenPublisher { 
    private static final Lock STATIC_LOCK = new ReentrantLock();
    private final MavenPublisher delegate;
 
    public StaticLockingMavenPublisher(MavenPublisher delegate) {
        this.delegate = delegate;
    } 
 
    public void publish(MavenNormalizedPublication publication, MavenArtifactRepository artifactRepository) {
        STATIC_LOCK.lock();
        try { 
            delegate.publish(publication, artifactRepository);
        } finally { 
            STATIC_LOCK.unlock();
        } 
    } 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:lock, unlock
 
	private ArrayList<T> array = new ArrayList<T>();
	private final ReentrantLock lock = new ReentrantLock();
	 
	public void push(T obj) {
		lock.lock();
		array.add(obj);
		lock.unlock();
	} 
	 
	public T pop() { 
		T ret = null;
		 
		lock.lock();
		 
		int s = array.size();
		if(s > 0)
			ret = array.remove( s-1 );
		 
		lock.unlock();
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
 
public class Synchronizer { 
 
    private final Lock lock = new ReentrantLock();
 
    public <T> T synchronize(Factory<T> factory) {
        lock.lock();
        try { 
            return factory.create();
        } finally { 
            lock.unlock();
        } 
    } 
 
    public void synchronize(Runnable operation) {
        lock.lock();
        try { 
            operation.run();
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:lock, unlock
    //System.out.println("NRT: set finish"); 
 
    finish = true;
 
    // So thread wakes up and notices it should finish: 
    reopenLock.lock();
    try { 
      reopenCond.signal();
    } finally { 
      reopenLock.unlock();
    } 
 
    try { 
      join();
    } catch (InterruptedException ie) {
      throw new ThreadInterruptedException(ie);
    } 
 
    // Max it out so any waiting search threads will return: 
    searchingGen = Long.MAX_VALUE;
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
import java.util.concurrent.locks.ReentrantLock;
 
class EmbeddedDaemonStarter implements DaemonStarter, Stoppable { 
    private final Factory<Daemon> daemonFactory;
    private final List<Daemon> daemons = new ArrayList<Daemon>();
    private final Lock daemonsLock = new ReentrantLock();
 
    public EmbeddedDaemonStarter(Factory<Daemon> daemonFactory) {
        this.daemonFactory = daemonFactory;
    } 
 
    public DaemonStartupInfo startDaemon() { 
        Daemon daemon = daemonFactory.create();
        startDaemon(daemon);
        return new DaemonStartupInfo(daemon.getUid(), daemon.getAddress(), null);
    } 
 
    public void startDaemon(Daemon daemon) {
        daemonsLock.lock();
        try { 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
import java.io.Closeable;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
 
public class SynchronizedToolingImplementationLoader implements ToolingImplementationLoader, Closeable {
    private final Lock lock = new ReentrantLock();
    private final ToolingImplementationLoader delegate;
 
    public SynchronizedToolingImplementationLoader(ToolingImplementationLoader delegate) {
        this.delegate = delegate;
    } 
 
    public ConsumerConnection create(Distribution distribution, ProgressLoggerFactory progressLoggerFactory, ConnectionParameters connectionParameters, BuildCancellationToken cancellationToken) {
        if (lock.tryLock()) {
            try { 
                return delegate.create(distribution, progressLoggerFactory, connectionParameters, cancellationToken);
            } finally { 
                lock.unlock();
            } 
        } 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 ReentrantLock Questions & Answers:

See Code Examples for Java 8 ReentrantLock Methods: