本文整理汇总了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();
}
示例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);
}
示例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;
}
示例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);
}
示例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>();
}
示例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();
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
示例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());
}
示例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());
}
示例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());
}