本文整理汇总了Java中java.util.concurrent.locks.ReadWriteLock.readLock方法的典型用法代码示例。如果您正苦于以下问题:Java ReadWriteLock.readLock方法的具体用法?Java ReadWriteLock.readLock怎么用?Java ReadWriteLock.readLock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.concurrent.locks.ReadWriteLock
的用法示例。
在下文中一共展示了ReadWriteLock.readLock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: App
import java.util.concurrent.locks.ReadWriteLock; //导入方法依赖的package包/类
public App(AMContext context) {
super(App.class.getName());
this.context = context;
stateMachine = stateMachineFactory.make(this);
ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
this.readLock = readWriteLock.readLock();
this.writeLock = readWriteLock.writeLock();
this.launchTime = context.getStartTime();
shouldRetry = false;
diagnostics = new ArrayList<String>();
stateTimeOutMs =
context.getConf().getLong(AngelConf.ANGEL_AM_APPSTATE_TIMEOUT_MS,
AngelConf.DEFAULT_ANGEL_AM_APPSTATE_TIMEOUT_MS);
stateToTsMap = new HashMap<AppState, Long>();
stateToTsMap.put(AppState.NEW, context.getClock().getTime());
stopped = new AtomicBoolean(false);
}
示例2: LocalTranslog
import java.util.concurrent.locks.ReadWriteLock; //导入方法依赖的package包/类
public LocalTranslog(TranslogConfig config) throws IOException {
super(config.getShardId(), config.getIndexSettings());
ReadWriteLock rwl = new ReentrantReadWriteLock();
readLock = new ReleasableLock(rwl.readLock());
writeLock = new ReleasableLock(rwl.writeLock());
this.translogPath = config.getTranslogPath();
// clean all files
Files.createDirectories(this.translogPath);
Files.walkFileTree(this.translogPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file,
BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}
});
// create a new directory
writeChannel = FileChannel.open(this.translogPath.resolve(getFileNameFromId(tmpTranslogGeneration.get())), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE);
writtenOffset = 0;
}
示例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: AMWorkerGroup
import java.util.concurrent.locks.ReadWriteLock; //导入方法依赖的package包/类
/**
* Create a AMWorkerGroup
* @param groupId worker group id
* @param context master context
* @param workerMap workers contains in worker group
* @param leader leader worker of worker group
* @param splitIndex training data block index assgined to this worker group
*/
public AMWorkerGroup(WorkerGroupId groupId, AMContext context, Map<WorkerId, AMWorker> workerMap,
WorkerId leader, int splitIndex) {
this.context = context;
this.groupId = groupId;
this.workerMap = workerMap;
this.leader = leader;
this.splitIndex = splitIndex;
ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
readLock = readWriteLock.readLock();
writeLock = readWriteLock.writeLock();
stateMachine = stateMachineFactory.make(this);
diagnostics = new ArrayList<String>();
successWorkerSet = new HashSet<WorkerId>();
failedWorkerSet = new HashSet<WorkerId>();
killedWorkerSet = new HashSet<WorkerId>();
}
示例5: 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);
}
示例6: 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>();
}
示例7: setInternalRegionArguments
import java.util.concurrent.locks.ReadWriteLock; //导入方法依赖的package包/类
@Override
protected void setInternalRegionArguments(InternalRegionArguments ira) {
// PR specific
PartitionedRegion pr = mock(PartitionedRegion.class);
BucketAdvisor ba = mock(BucketAdvisor.class);
ReadWriteLock primaryMoveLock = new ReentrantReadWriteLock();
Lock activeWriteLock = primaryMoveLock.readLock();
when(ba.getActiveWriteLock()).thenReturn(activeWriteLock);
when(ba.isPrimary()).thenReturn(true);
ira.setPartitionedRegion(pr).setPartitionedRegionBucketRedundancy(1).setBucketAdvisor(ba);
}
示例8: DiskWriterTask
import java.util.concurrent.locks.ReadWriteLock; //导入方法依赖的package包/类
DiskWriterTask(int partitionID, int writerID, BlockingQueue<FileBlock> queue) {
super(partitionID, writerID);
this.queue = queue;
hasToRun = new AtomicBoolean(true);
final ReadWriteLock rwl = new ReentrantReadWriteLock();
countersRLock = rwl.readLock();
countersWLock = rwl.writeLock();
final boolean hasP = (System.getProperty("fdt.doNotForceOnClose") != null);
doNotForceOnClose = (hasP) ? Boolean.getBoolean("fdt.doNotForceOnClose") : true;
}
示例9: KeyAuthorizationKeyProvider
import java.util.concurrent.locks.ReadWriteLock; //导入方法依赖的package包/类
/**
* The constructor takes a {@link KeyProviderCryptoExtension} and an
* implementation of <code>KeyACLs</code>. All calls are delegated to the
* provider keyProvider after authorization check (if required)
* @param keyProvider
* @param acls
*/
public KeyAuthorizationKeyProvider(KeyProviderCryptoExtension keyProvider,
KeyACLs acls) {
super(keyProvider, null);
this.provider = keyProvider;
this.acls = acls;
ReadWriteLock lock = new ReentrantReadWriteLock(true);
readLock = lock.readLock();
writeLock = lock.writeLock();
}
示例10: KeyAuthorizationKeyProvider
import java.util.concurrent.locks.ReadWriteLock; //导入方法依赖的package包/类
/**
* The constructor takes a {@link KeyProviderCryptoExtension} and an
* implementation of <code>KeyACLs</code>. All calls are delegated to the
* provider keyProvider after authorization check (if required)
* @param keyProvider the key provider
* @param acls the Key ACLs
*/
public KeyAuthorizationKeyProvider(KeyProviderProxyReEncryptionExtension keyProvider,
KeyACLs acls) {
super(keyProvider, null);
this.provider = keyProvider;
this.acls = acls;
ReadWriteLock lock = new ReentrantReadWriteLock(true);
readLock = lock.readLock();
writeLock = lock.writeLock();
}
示例11: TranslogWriter
import java.util.concurrent.locks.ReadWriteLock; //导入方法依赖的package包/类
public TranslogWriter(ShardId shardId, long generation, ChannelReference channelReference) throws IOException {
super(generation, channelReference, channelReference.getChannel().position());
this.shardId = shardId;
ReadWriteLock rwl = new ReentrantReadWriteLock();
readLock = new ReleasableLock(rwl.readLock());
writeLock = new ReleasableLock(rwl.writeLock());
this.writtenOffset = channelReference.getChannel().position();
this.lastSyncedOffset = channelReference.getChannel().position();;
}
示例12: ConfigurationFactoryImpl
import java.util.concurrent.locks.ReadWriteLock; //导入方法依赖的package包/类
public ConfigurationFactoryImpl ()
{
final ReadWriteLock lock = new ReentrantReadWriteLock ();
this.readLock = lock.readLock ();
this.writeLock = lock.writeLock ();
final BundleContext context = FrameworkUtil.getBundle ( DataContext.class ).getBundleContext ();
this.executor = new ScheduledExportedExecutorService ( "org.eclipse.scada.da.server.exporter.rest", 1 );
this.hiveSource = new ServiceListenerHiveSource ( context, this.executor );
this.hiveSource.open ();
}
示例13: 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);
}
示例14: 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);
}
示例15: testReadLockDoesNotBlockReadLock
import java.util.concurrent.locks.ReadWriteLock; //导入方法依赖的package包/类
@Test
public void testReadLockDoesNotBlockReadLock() {
final ReadWriteLock rwl = new CountingReadWriteLock();
final Lock r = rwl.readLock();
r.lock();
assertTrue(r.tryLock());
}