Example usage for java.util.concurrent.locks ReentrantLock ReentrantLock

List of usage examples for java.util.concurrent.locks ReentrantLock ReentrantLock

Introduction

In this page you can find the example usage for java.util.concurrent.locks ReentrantLock ReentrantLock.

Prototype

public ReentrantLock() 

Source Link

Document

Creates an instance of ReentrantLock .

Usage

From source file:tools.datasync.db2db.net.TCPConnection.java

public TCPConnection() {
    logger.info("Creating TCP Connection service...");
    handlers = new ArrayList<SyncDataHandler>();
    connectionLock = new ReentrantLock();
    isConnected = new AtomicBoolean(false);
}

From source file:org.apache.hadoop.hbase.util.ByteBufferArray.java

/**
 * We allocate a number of byte buffers as the capacity. In order not to out
 * of the array bounds for the last byte(see {@link ByteBufferArray#multiple}), 
 * we will allocate one additional buffer with capacity 0;
 * @param capacity total size of the byte buffer array
 * @param directByteBuffer true if we allocate direct buffer
 *//* ww w .j a  v  a2  s  .  c  o m*/
public ByteBufferArray(long capacity, boolean directByteBuffer) {
    this.bufferSize = DEFAULT_BUFFER_SIZE;
    if (this.bufferSize > (capacity / 16))
        this.bufferSize = (int) roundUp(capacity / 16, 32768);
    this.bufferCount = (int) (roundUp(capacity, bufferSize) / bufferSize);
    LOG.info("Allocating buffers total=" + StringUtils.byteDesc(capacity) + ", sizePerBuffer="
            + StringUtils.byteDesc(bufferSize) + ", count=" + bufferCount + ", direct=" + directByteBuffer);
    buffers = new ByteBuffer[bufferCount + 1];
    locks = new Lock[bufferCount + 1];
    for (int i = 0; i <= bufferCount; i++) {
        locks[i] = new ReentrantLock();
        if (i < bufferCount) {
            buffers[i] = directByteBuffer ? ByteBuffer.allocateDirect(bufferSize)
                    : ByteBuffer.allocate(bufferSize);
        } else {
            buffers[i] = ByteBuffer.allocate(0);
        }

    }
}

From source file:com.joyent.manta.client.multipart.EncryptionState.java

/**
 * <p>Creates a new multipart encryption state object.</p>
 *
 * <p>NOTE: This class is tightly bound to the lifecycle of the
 * encrypted MPU manager.  In particular the streams are now
 * instantiated as part of the constructor and must be set before
 * use.</p>/*from   w w w.  ja  va 2  s .  c  o m*/
 *
 * @param encryptionContext encryption cipher state object
 */
public EncryptionState(final EncryptionContext encryptionContext) {
    this.encryptionContext = encryptionContext;
    this.lock = new ReentrantLock();
}

From source file:ai.grakn.engine.backgroundtasks.InMemoryTaskManager.java

private InMemoryTaskManager() {
    instantiatedTasks = new ConcurrentHashMap<>();
    stateStorage = InMemoryStateStorage.getInstance();
    stateUpdateLock = new ReentrantLock();

    ConfigProperties properties = ConfigProperties.getInstance();
    schedulingService = Executors.newScheduledThreadPool(1);
    executorService = Executors.newFixedThreadPool(properties.getAvailableThreads());
}

From source file:ch.algotrader.adapter.fix.DefaultFixAdapter.java

public DefaultFixAdapter(final SocketInitiator socketInitiator, final LookupService lookupService,
        final FixEventScheduler eventScheduler, final OrderIdGenerator orderIdGenerator) {
    Validate.notNull(socketInitiator, "SocketInitiator is null");
    Validate.notNull(lookupService, "LookupService is null");
    Validate.notNull(eventScheduler, "FixEventScheduler is null");
    Validate.notNull(orderIdGenerator, "OrderIdGenerator is null");

    this.socketInitiator = socketInitiator;
    this.lookupService = lookupService;
    this.eventScheduler = eventScheduler;
    this.orderIdGenerator = orderIdGenerator;
    this.lock = new ReentrantLock();
}

From source file:org.apache.hadoop.yarn.server.sharedcachemanager.CleanerService.java

public CleanerService(SCMStore store) {
    super("CleanerService");
    this.store = store;
    this.cleanerTaskLock = new ReentrantLock();
}

From source file:org.apache.hadoop.lib.service.instrumentation.InstrumentationService.java

@Override
@SuppressWarnings("unchecked")
public void init() throws ServiceException {
    timersSize = getServiceConfig().getInt(CONF_TIMERS_SIZE, 10);
    counterLock = new ReentrantLock();
    timerLock = new ReentrantLock();
    variableLock = new ReentrantLock();
    samplerLock = new ReentrantLock();
    Map<String, VariableHolder> jvmVariables = new ConcurrentHashMap<String, VariableHolder>();
    counters = new ConcurrentHashMap<String, Map<String, AtomicLong>>();
    timers = new ConcurrentHashMap<String, Map<String, Timer>>();
    variables = new ConcurrentHashMap<String, Map<String, VariableHolder>>();
    samplers = new ConcurrentHashMap<String, Map<String, Sampler>>();
    samplersList = new ArrayList<Sampler>();
    all = new LinkedHashMap<String, Map<String, ?>>();
    all.put("os-env", System.getenv());
    all.put("sys-props", (Map<String, ?>) (Map) System.getProperties());
    all.put("jvm", jvmVariables);
    all.put("counters", (Map) counters);
    all.put("timers", (Map) timers);
    all.put("variables", (Map) variables);
    all.put("samplers", (Map) samplers);

    jvmVariables.put("free.memory", new VariableHolder<Long>(new Instrumentation.Variable<Long>() {
        @Override//  ww w . ja  v  a  2 s.  co m
        public Long getValue() {
            return Runtime.getRuntime().freeMemory();
        }
    }));
    jvmVariables.put("max.memory", new VariableHolder<Long>(new Instrumentation.Variable<Long>() {
        @Override
        public Long getValue() {
            return Runtime.getRuntime().maxMemory();
        }
    }));
    jvmVariables.put("total.memory", new VariableHolder<Long>(new Instrumentation.Variable<Long>() {
        @Override
        public Long getValue() {
            return Runtime.getRuntime().totalMemory();
        }
    }));
}

From source file:info.pancancer.arch3.worker.WorkflowRunner.java

/**
 * Get the stderr of the running command.
 *
 * @return/*from w w  w .  jav  a 2  s . co m*/
 */
public String getStdErr() {
    String s;
    Lock lock = new ReentrantLock();
    lock.lock();
    try {
        this.errorStream.flush();
        s = this.errorStream.getAllLinesAsString();
    } finally {
        lock.unlock();
    }
    return s;
}

From source file:at.newmedialab.ldclient.service.LDCache.java

private void lockResource(URI resource) {
    Lock lock;/*ww w.  ja va  2  s.  c  om*/
    synchronized (resourceLocks) {
        lock = resourceLocks.get(resource);
        if (lock == null) {
            lock = new ReentrantLock();
            resourceLocks.put(resource, lock);
        }
    }
    lock.lock();
}

From source file:org.apache.openjpa.kernel.ExtentImpl.java

/**
 * Constructor.//from w  w w . j a  va 2  s.com
 *
 * @param broker the owning broker
 * @param type the candidate class
 * @param subs whether subclasses are included in the extent
 */
ExtentImpl(Broker broker, Class<T> type, boolean subs, FetchConfiguration fetch) {
    _broker = broker;
    _type = type;
    _subs = subs;
    if (fetch != null)
        _fc = fetch;
    else
        _fc = (FetchConfiguration) broker.getFetchConfiguration().clone();
    _ignore = broker.getIgnoreChanges();
    if (broker.getMultithreaded())
        _lock = new ReentrantLock();
    else
        _lock = null;
}