當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。