Code example for Lock

Methods: locktryLockunlock

0
    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();
            logger.completed();
        } 
    } 
 
    public void close() {