Lock unlock - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Lock unlock method.

This code example shows how to use the following methods:lock, unlock
    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
This code example shows how to use the following methods:lock, tryLock, unlock
    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();
            } 
        } 
        ProgressLogger logger = progressLoggerFactory.newOperation(SynchronizedToolingImplementationLoader.class);
        logger.setDescription("Wait for the other thread to finish acquiring the distribution");
        logger.started();
        lock.lock();
        try { 
            return delegate.create(distribution, progressLoggerFactory, connectionParameters, cancellationToken);
        } finally { 
            lock.unlock();

9
CodeRank
This code example shows how to use the following methods:lock, unlock
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();
        } finally { 
            lock.unlock();
        } 
9
CodeRank
This code example shows how to use the following methods:lock, unlock
          monitorLock(); 
        } 
      } 
   
      private void syncLock() { 
        lock1.lock();
        try { 
          try { 
            barrier.await();
          } catch (Exception e) {
          } 
          goSyncDeadlock(); 
        } finally { 
          lock1.unlock();
        } 
      } 
   
      private void goSyncDeadlock() { 
        try { 
          barrier.await();
8
CodeRank
This code example shows how to use the following methods:lock, unlock
        startDaemon(daemon);
        return new DaemonStartupInfo(daemon.getUid(), daemon.getAddress(), null);
    } 
 
    public void startDaemon(Daemon daemon) {
        daemonsLock.lock();
        try { 
            daemons.add(daemon);
        } finally { 
            daemonsLock.unlock();
        } 
 
        daemon.start();
    } 
 
    public void stop() { 
        List<Daemon> daemonsToStop;
 
        daemonsLock.lock();
        try { 
9
CodeRank
This code example shows how to use the following methods:sleep, lock, unlock
         * @see Runnable#run() 
         */ 
        @Override 
        public void run() { 
            // lock it! 
            this.lock.lock();
            // process(sleep) for the specified time 
            try { 
                Thread.sleep(this.processingTime);
            } catch (InterruptedException e) {
                // ignore 
            } finally { 
                // unlock 
                this.lock.unlock();
                // let any waiting threads know that we are done processing 
                this.latch.countDown();
            } 
        } 
    } 
 
8
CodeRank
This code example shows how to use the following methods:lock, unlock
      } 
    } 
 
    public long getCount() 
    { 
      _lock.lock();
      try 
      { 
        return _count;
      } 
      finally 
      { 
        _lock.unlock();
      } 
    } 
 
    public void waitForEvent(long count, ZKPersistentConnection.Event event, long timeout,
                             TimeUnit timeoutUnit)
            throws TimeoutException, InterruptedException 
    { 
8
CodeRank
This code example shows how to use the following methods:lock, newCondition, unlock
        Init, Stopped
    } 
 
    private static final int MAX_QUEUE_SIZE = 200;
    private final Lock lock = new ReentrantLock();
    private final Condition condition = lock.newCondition();
    private final LinkedList<T> queue = new LinkedList<T>();
    private final Executor executor;
    private final int maxQueueSize;
    private int dispatchers;
    private State state;
 
    public AsyncDispatch(Executor executor) {
        this(executor, null, MAX_QUEUE_SIZE);
    } 
 
    public AsyncDispatch(Executor executor, final Dispatch<? super T> dispatch) {
        this(executor, dispatch, MAX_QUEUE_SIZE);
    } 
 

7
CodeRank
This code example shows how to use the following methods:lock, unlock
            lock.unlock();
        } 
    } 
 
    public void dispatch(T message) {
        lock.lock();
        try { 
            if (dispatch == null) {
                queue.add(message);
            } else { 
                dispatch.dispatch(message);
            } 
        } finally { 
            lock.unlock();
        } 
    } 
 
    public void stop() { 
        lock.lock();
        try { 
9
CodeRank
This code example shows how to use the following methods:lock, unlock
 
    public FavListBean loadData() throws WeiboException { 
        FavListDao dao = new FavListDao(token);
        dao.setPage(page);
        FavListBean result = null;
        lock.lock();
 
        try { 
            result = dao.getGSONMsgList();
        } finally { 
            lock.unlock();
        } 
 
 
        return result;
    } 
 
} 
 
8
CodeRank

Related Lock unlock Questions & Answers:

unlock Method Overview
Releases the lock.
See Code Examples for other Java 8 Lock Methods: