当前位置: 首页>>代码示例>>Java>>正文


Java ReadWriteLock类代码示例

本文整理汇总了Java中java.util.concurrent.locks.ReadWriteLock的典型用法代码示例。如果您正苦于以下问题:Java ReadWriteLock类的具体用法?Java ReadWriteLock怎么用?Java ReadWriteLock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ReadWriteLock类属于java.util.concurrent.locks包,在下文中一共展示了ReadWriteLock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: RocksDBStore

import java.util.concurrent.locks.ReadWriteLock; //导入依赖的package包/类
public RocksDBStore(String name, ColumnFamilyDescriptor family, ColumnFamilyHandle handle, RocksDB db, int stripes) {
  super();
  this.family = family;
  this.name = name;
  this.db = db;
  this.parallel = stripes;
  this.handle = handle;
  this.sharedLocks = new AutoCloseableLock[stripes];
  this.exclusiveLocks = new AutoCloseableLock[stripes];

  for (int i = 0; i < stripes; i++) {
    ReadWriteLock core = new ReentrantReadWriteLock();
    sharedLocks[i] = new AutoCloseableLock(core.readLock());
    exclusiveLocks[i] = new AutoCloseableLock(core.writeLock());
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:RocksDBStore.java

示例2: 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);
}
 
开发者ID:Tencent,项目名称:angel,代码行数:20,代码来源:App.java

示例3: 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

示例4: AMTask

import java.util.concurrent.locks.ReadWriteLock; //导入依赖的package包/类
public AMTask(TaskId id, AMTask amTask) {
  state = AMTaskState.NEW;
  taskId = id;
  metrics = new HashMap<String, String>();
  startTime = -1;
  finishTime = -1;

  matrixIdToClockMap = new Int2IntOpenHashMap();
  // if amTask is not null, we should clone task state from it
  if (amTask == null) {
    iteration = 0;
    progress = 0.0f;
  } else {
    iteration = amTask.getIteration();
    progress = amTask.getProgress();
    matrixIdToClockMap.putAll(amTask.matrixIdToClockMap);
  }

  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  readLock = readWriteLock.readLock();
  writeLock = readWriteLock.writeLock();
}
 
开发者ID:Tencent,项目名称:angel,代码行数:23,代码来源:AMTask.java

示例5: 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

示例6: 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>();
}
 
开发者ID:Tencent,项目名称:angel,代码行数:26,代码来源:AMWorkerGroup.java

示例7: main

import java.util.concurrent.locks.ReadWriteLock; //导入依赖的package包/类
public static void main(String[] args) {
    //创建并发访问的账户
    MyCount myCount = new MyCount("95599200901215522", 10000);
    //创建一个锁对象
    ReadWriteLock lock = new ReentrantReadWriteLock(false);
    //创建一个线程池
    ExecutorService pool = Executors.newFixedThreadPool(2);
    //创建一些并发访问用户,一个信用卡,存的存,取的取,好热闹啊
    User u1 = new User("张三", myCount, -4000, lock, true);
    User u2 = new User("张三他爹", myCount, 6000, lock, false);
    User u3 = new User("张三他弟", myCount, -8000, lock, false);
    User u4 = new User("张三", myCount, 800, lock, false);
    User u5 = new User("张三他爹", myCount, 0, lock, true);
    //在线程池中执行各个用户的操作
    pool.execute(u1);
    pool.execute(u2);
    pool.execute(u3);
    pool.execute(u4);
    pool.execute(u5);
    //关闭线程池
    pool.shutdown();
}
 
开发者ID:sean417,项目名称:LearningOfThinkInJava,代码行数:23,代码来源:ReadWriteLockDemo1.java

示例8: decorateDestructionCallback

import java.util.concurrent.locks.ReadWriteLock; //导入依赖的package包/类
public Context<ReadWriteLock> decorateDestructionCallback(final Runnable callback) {
    if (callback == null) {
        return null;
    }
    final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
    return new Context<ReadWriteLock>(new Runnable() {
        public void run() {
            Lock lock = readWriteLock.writeLock();
            lock.lock();
            try {
                callback.run();
            } finally {
                lock.unlock();
            }
        }
    }, readWriteLock);
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:18,代码来源:StandardBeanLifecycleDecorator.java

示例9: weakImplementations

import java.util.concurrent.locks.ReadWriteLock; //导入依赖的package包/类
private static List<Striped<?>> weakImplementations() {
  return ImmutableList.<Striped<?>>builder()
      .add(new Striped.SmallLazyStriped<ReadWriteLock>(50, READ_WRITE_LOCK_SUPPLIER))
      .add(new Striped.SmallLazyStriped<ReadWriteLock>(64, READ_WRITE_LOCK_SUPPLIER))
      .add(new Striped.LargeLazyStriped<ReadWriteLock>(50, READ_WRITE_LOCK_SUPPLIER))
      .add(new Striped.LargeLazyStriped<ReadWriteLock>(64, READ_WRITE_LOCK_SUPPLIER))
      .add(new Striped.SmallLazyStriped<Lock>(50, LOCK_SUPPLER))
      .add(new Striped.SmallLazyStriped<Lock>(64, LOCK_SUPPLER))
      .add(new Striped.LargeLazyStriped<Lock>(50, LOCK_SUPPLER))
      .add(new Striped.LargeLazyStriped<Lock>(64, LOCK_SUPPLER))
      .add(new Striped.SmallLazyStriped<Semaphore>(50, SEMAPHORE_SUPPLER))
      .add(new Striped.SmallLazyStriped<Semaphore>(64, SEMAPHORE_SUPPLER))
      .add(new Striped.LargeLazyStriped<Semaphore>(50, SEMAPHORE_SUPPLER))
      .add(new Striped.LargeLazyStriped<Semaphore>(64, SEMAPHORE_SUPPLER))
      .build();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:StripedTest.java

示例10: loadFromDisk

import java.util.concurrent.locks.ReadWriteLock; //导入依赖的package包/类
protected StoreImage loadFromDisk(Path imgFile, long id) {
	byte[] imgData = null;
	
	// Try aquiring a lock for a file.
	ReadWriteLock l = getIDLock(id);
	l.readLock().lock();
	try {
		imgData = Files.readAllBytes(imgFile);
	} catch (IOException ioException) {
		log.warn("An IOException occured while trying to read the file \"" + imgFile.toAbsolutePath()
				+ "\" from disk. Returning null.", ioException);
	} finally {
		l.readLock().unlock();
	}
	
	if (imgData == null) {
		return null;
	}
	
	ImageSize size = imgDB.getImageSize(id);
	if (size == null) {
		return null;
	}
	
	return new StoreImage(id, imgData, size);
}
 
开发者ID:DescartesResearch,项目名称:Pet-Supply-Store,代码行数:27,代码来源:DriveStorage.java

示例11: 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

示例12: ContainerImpl

import java.util.concurrent.locks.ReadWriteLock; //导入依赖的package包/类
public ContainerImpl(Configuration conf, Dispatcher dispatcher,
    NMStateStoreService stateStore, ContainerLaunchContext launchContext,
    Credentials creds, NodeManagerMetrics metrics,
    ContainerTokenIdentifier containerTokenIdentifier) {
  this.daemonConf = conf;
  this.dispatcher = dispatcher;
  this.stateStore = stateStore;
  this.launchContext = launchContext;
  this.containerTokenIdentifier = containerTokenIdentifier;
  this.containerId = containerTokenIdentifier.getContainerID();
  this.resource = containerTokenIdentifier.getResource();
  this.diagnostics = new StringBuilder();
  this.credentials = creds;
  this.metrics = metrics;
  user = containerTokenIdentifier.getApplicationSubmitter();
  ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  this.readLock = readWriteLock.readLock();
  this.writeLock = readWriteLock.writeLock();

  stateMachine = stateMachineFactory.make(this);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:22,代码来源:ContainerImpl.java

示例13: GenericDynamoDB

import java.util.concurrent.locks.ReadWriteLock; //导入依赖的package包/类
public GenericDynamoDB(AmazonDynamoDB client, AWSCredentialsProvider awsCredentials,
                       ClientConfiguration clientConfiguration,
                       SecretsGroupIdentifier groupIdentifier, Class<Entry> clazz, Converters converters,
                       ReadWriteLock readWriteLock) {
    this.clazz = clazz;
    buildMappings();
    this.converters = converters;
    this.awsCredentials = awsCredentials;
    this.clientConfiguration = clientConfiguration;
    this.client = client;
    this.region = RegionUtils.getRegion(groupIdentifier.region.getName());
    this.readWriteLock = readWriteLock;

    RegionLocalResourceName resourceName = new RegionLocalResourceName(groupIdentifier);
    this.tableName = resourceName.toString();
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:17,代码来源:GenericDynamoDB.java

示例14: GenericFile

import java.util.concurrent.locks.ReadWriteLock; //导入依赖的package包/类
public GenericFile(java.io.File path,
                   Converters converters,
                   Encryptor encryptor,
                   EncryptionContext encryptionContext,
                   Class<Entry> clazz,
                   ReadWriteLock readWriteLock) {
    this.file = path;
    this.converters = converters;
    this.clazz = clazz;
    this.readWriteLock = readWriteLock;
    this.encryptor = encryptor;
    this.encryptionContext = encryptionContext;
    buildMappings();

    open();
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:17,代码来源:GenericFile.java

示例15: backup

import java.util.concurrent.locks.ReadWriteLock; //导入依赖的package包/类
public void backup(SecretsGroupIdentifier group, Store backupStore, boolean failIfBackupStoreAlreadyExists) {
    ReadWriteLock readWriteLock = getReadWriteLock(group);
    readWriteLock.writeLock().lock();

    try {
        Store currentStore = getCurrentStore(group, readWriteLock);

        if (backupStore.exists()) {
            if (failIfBackupStoreAlreadyExists) {
                throw new AlreadyExistsException("The store to backup to already exists");
            }
            backupStore.delete();
        }
        backupStore.create();
        currentStore.stream().forEach(backupStore::create);
        backupStore.close();
    } finally {
        readWriteLock.writeLock().unlock();
    }
}
 
开发者ID:schibsted,项目名称:strongbox,代码行数:21,代码来源:DefaultSecretsGroupManager.java


注:本文中的java.util.concurrent.locks.ReadWriteLock类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。