當前位置: 首頁>>代碼示例>>Java>>正文


Java ReadWriteLock.writeLock方法代碼示例

本文整理匯總了Java中java.util.concurrent.locks.ReadWriteLock.writeLock方法的典型用法代碼示例。如果您正苦於以下問題:Java ReadWriteLock.writeLock方法的具體用法?Java ReadWriteLock.writeLock怎麽用?Java ReadWriteLock.writeLock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.concurrent.locks.ReadWriteLock的用法示例。


在下文中一共展示了ReadWriteLock.writeLock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: AMPSAgent

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
public AMPSAgent(AMContext context, PSAgentId id, Location location) {
  this.context = context;
  this.id = id;
  this.location = location;
  this.diagnostics = new ArrayList<String>();
  this.failedAttempts = new ArrayList<PSAgentAttemptId>();
  this.attempts = new HashMap<PSAgentAttemptId, PSAgentAttempt>();
  if (context.getRunningMode() == RunningMode.ANGEL_PS_PSAGENT) {
    this.stateMachine = stateMachineFactoryForAllMode.make(this);
  } else {
    this.stateMachine = stateMachineFactoryForPSMode.make(this);
  }

  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  this.readLock = readWriteLock.readLock();
  this.writeLock = readWriteLock.writeLock();
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:18,代碼來源:AMPSAgent.java

示例2: AMWorker

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
public AMWorker(WorkerId id, AMContext context, List<TaskId> taskIds) {
  this.id = id;
  this.context = context;
  this.taskIds = taskIds;

  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  readLock = readWriteLock.readLock();
  writeLock = readWriteLock.writeLock();
  stateMachine = stateMachineFactory.make(this);
  metrics = new HashMap<String, String>();
  diagnostics = new ArrayList<String>();    
  attempts = new HashMap<WorkerAttemptId, WorkerAttempt>();
  failedAttempts = new HashSet<WorkerAttemptId>();
  
  maxAttempts =
      context.getConf().getInt(AngelConf.ANGEL_WORKER_MAX_ATTEMPTS,
          AngelConf.DEFAULT_WORKER_MAX_ATTEMPTS);
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:19,代碼來源:AMWorker.java

示例3: Translog

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
public Translog(TranslogConfig config, String nodeId) {
    super(config.getShardId(), config.getIndexSettings());
    this.config = null;
    recoveredTranslogs = null;
    syncScheduler = null;
    bigArrays = null;
    ReadWriteLock rwl = new ReentrantReadWriteLock();
    readLock = new ReleasableLock(rwl.readLock());
    writeLock = new ReleasableLock(rwl.writeLock());
    location = null;
    current = null;
    currentCommittingTranslog = null;
    lastCommittedTranslogFileGeneration = -1; 
    config = null;
    translogUUID = null;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:17,代碼來源:Translog.java

示例4: AMParameterServer

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
public AMParameterServer(String ip, ParameterServerId id, AMContext context) {
  this.ip = ip;
  this.id = id;
  this.context = context;
  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  readLock = readWriteLock.readLock();
  writeLock = readWriteLock.writeLock();
  stateMachine = stateMachineFactory.make(this);
  attempts = new HashMap<PSAttemptId, PSAttempt>(2);
  this.failedAttempts = new HashSet<PSAttemptId>(2);
  maxAttempts =
      context.getConf().getInt(AngelConf.ANGEL_PS_MAX_ATTEMPTS,
          AngelConf.DEFAULT_PS_MAX_ATTEMPTS);
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:15,代碼來源:AMParameterServer.java

示例5: PSAttempt

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
/**
 * Init the Attempt for PS
 * @param ip excepted host for this ps attempt
 * @param psId ps id
 * @param attemptIndex attempt index
 * @param amContext Master context
 */
public PSAttempt(String ip, ParameterServerId psId, int attemptIndex, AMContext amContext) {
  this.expectedIp = ip;
  attemptId = new PSAttemptId(psId, attemptIndex);
  this.context = amContext;
  stateMachine = stateMachineFactory.make(this);
  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  readLock = readWriteLock.readLock();
  writeLock = readWriteLock.writeLock();
  metrices = new HashMap<String, String>();
  diagnostics = new ArrayList<String>();
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:19,代碼來源:PSAttempt.java

示例6: YarnContainerAllocator

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
public YarnContainerAllocator(AMContext context) {
  super(YarnContainerAllocator.class.getName());
  this.context = context;
  this.recordFactory = RecordFactoryProvider.getRecordFactory(null);
  stopped = new AtomicBoolean(false);
  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  readLock = readWriteLock.readLock();
  writeLock = readWriteLock.writeLock();
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:10,代碼來源:YarnContainerAllocator.java

示例7: LocalizedResource

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
public LocalizedResource(LocalResourceRequest rsrc, Dispatcher dispatcher) {
  this.rsrc = rsrc;
  this.dispatcher = dispatcher;
  this.ref = new LinkedList<ContainerId>();

  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  this.readLock = readWriteLock.readLock();
  this.writeLock = readWriteLock.writeLock();

  this.stateMachine = stateMachineFactory.make(this);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:12,代碼來源:LocalizedResource.java

示例8: MemoryTokenStore

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
public MemoryTokenStore() {
    this.cache = CacheBuilder.newBuilder().softValues().expireAfterAccess(120, TimeUnit.SECONDS)
            .build();
    ReadWriteLock lock = new ReentrantReadWriteLock();
    this.r = lock.readLock();
    this.w = lock.writeLock();
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:8,代碼來源:MemoryTokenStore.java

示例9: PSAgentAttempt

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
public PSAgentAttempt(PSAgentAttemptId attemptId, AMContext context, Location location) {
  this.id = attemptId;
  this.context = context;
  this.location = location;
  if (context.getRunningMode() == RunningMode.ANGEL_PS_PSAGENT) {
    stateMachine = stateMachineFactoryForAllMode.make(this);
  } else {
    stateMachine = stateMachineFactoryForPSMode.make(this);
  }

  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  readLock = readWriteLock.readLock();
  writeLock = readWriteLock.writeLock();
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:15,代碼來源:PSAgentAttempt.java

示例10: lockIfExists

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
public static boolean lockIfExists(final ReadWriteLock rwLock, boolean exclusive) {
    if (null == rwLock) {
        return false;
    }
    final Lock lock = exclusive ? rwLock.writeLock() : rwLock.readLock();
    return lockIfExists(lock);
}
 
開發者ID:yohlulz,項目名稱:MLE5109-Course-samples,代碼行數:8,代碼來源:LockUtils.java

示例11: Worker

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
/**
 * Instantiates a new Worker.
 *
 * @param conf            the conf
 * @param appId           the app id
 * @param user            the user
 * @param workerAttemptId the worker attempt id
 * @param masterLocation  the master location
 * @param initMinClock    the init min clock
 * @param isLeader        the is leader
 */
public Worker(Configuration conf, ApplicationId appId, String user,
    WorkerAttemptId workerAttemptId, Location masterLocation, int initMinClock,
    boolean isLeader) {
  this.conf = conf;
  this.stopped = new AtomicBoolean(false);
  this.workerInitFinishedFlag = new AtomicBoolean(false);
  this.exitedFlag = new AtomicBoolean(false);
  this.workerMetrics = new HashMap<String, String>();
  this.connection = TConnectionManager.getConnection(conf);

  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  readLockForTaskNum = readWriteLock.readLock();
  writeLockForTaskNum = readWriteLock.writeLock();

  activeTaskNum = conf.getInt(AngelConf.ANGEL_TASK_ACTUAL_NUM, 1);

  this.appId = appId;
  this.user = user;
  this.masterLocation = masterLocation;
  this.workerAttemptId = workerAttemptId;
  this.isLeader = isLeader;

  this.workerAttemptIdProto = ProtobufUtil.convertToIdProto(workerAttemptId);

  this.initMinClock = initMinClock;
  this.counterUpdater = new CounterUpdater();
  WorkerContext.get().setWorker(this);
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:40,代碼來源:Worker.java

示例12: testWriteLockWriteUnlock

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
@Test
public void testWriteLockWriteUnlock() {
  final ReadWriteLock rwl = new CountingReadWriteLock();
  final Lock w = rwl.writeLock();
  w.lock();
  w.unlock();
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:8,代碼來源:CountingReadWriteLockTest.java

示例13: testWriteLockBlocksReadLock

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
@Test
public void testWriteLockBlocksReadLock() {
  final ReadWriteLock rwl = new CountingReadWriteLock();
  final Lock w = rwl.writeLock();
  w.lock();
  final Lock r = rwl.readLock();
  assertFalse(r.tryLock());
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:9,代碼來源:CountingReadWriteLockTest.java

示例14: testWriteLockBlocksWriteLock

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
@Test
public void testWriteLockBlocksWriteLock() {
  final ReadWriteLock rwl = new CountingReadWriteLock();
  final Lock w = rwl.writeLock();
  w.lock();
  assertFalse(w.tryLock());
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:8,代碼來源:CountingReadWriteLockTest.java

示例15: testReadLockBlocksWriteLock

import java.util.concurrent.locks.ReadWriteLock; //導入方法依賴的package包/類
@Test
public void testReadLockBlocksWriteLock() {
  final ReadWriteLock rwl = new CountingReadWriteLock();
  final Lock r = rwl.readLock();
  r.lock();
  final Lock w = rwl.writeLock();
  assertFalse(w.tryLock());
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:9,代碼來源:CountingReadWriteLockTest.java


注:本文中的java.util.concurrent.locks.ReadWriteLock.writeLock方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。