readLock()源码实例Demo

java.util.concurrent.locks.ReentrantReadWriteLock#readLock()源码实例Demo

下面列出了java.util.concurrent.locks.ReentrantReadWriteLock#readLock() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: big-c   文件: RMNodeImpl.java
public RMNodeImpl(NodeId nodeId, RMContext context, String hostName,
    int cmPort, int httpPort, Node node, Resource capability, String nodeManagerVersion) {
  this.nodeId = nodeId;
  this.context = context;
  this.hostName = hostName;
  this.commandPort = cmPort;
  this.httpPort = httpPort;
  this.totalCapability = capability; 
  this.nodeAddress = hostName + ":" + cmPort;
  this.httpAddress = hostName + ":" + httpPort;
  this.node = node;
  this.healthReport = "Healthy";
  this.lastHealthReportTime = System.currentTimeMillis();
  this.nodeManagerVersion = nodeManagerVersion;

  this.latestNodeHeartBeatResponse.setResponseId(0);

  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();

  this.stateMachine = stateMachineFactory.make(this);
  
  this.nodeUpdateQueue = new ConcurrentLinkedQueue<UpdatedContainerInfo>();  
}
 
源代码2 项目: c2mon   文件: AbstractTagCacheObject.java
/**
 * The clone is provided with <b>new</b> locks: these do not lock access
 * to the object residing in the cache (the clone is no longer in the
 * cache).
 */
@Override
public Object clone() throws CloneNotSupportedException {
  AbstractTagCacheObject cacheObject = (AbstractTagCacheObject) super.clone();
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  cacheObject.readLock = lock.readLock();
  cacheObject.writeLock = lock.writeLock();
  if (dataTagQuality != null) {
    cacheObject.dataTagQuality = (DataTagQuality) dataTagQuality.clone();
  }
  cacheObject.alarmIds = (ArrayList<Long>) ((ArrayList<Long>) alarmIds).clone();
  cacheObject.ruleIds = (ArrayList<Long>) ((ArrayList<Long>) ruleIds).clone();
  if (cacheTimestamp != null) {
    cacheObject.cacheTimestamp = (Timestamp) cacheTimestamp.clone();
  }
  return cacheObject;
}
 
源代码3 项目: hadoop   文件: RMStateStore.java
public RMStateStore() {
  super(RMStateStore.class.getName());
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();
  stateMachine = stateMachineFactory.make(this);
}
 
源代码4 项目: big-c   文件: AbstractYarnScheduler.java
/**
 * Construct the service.
 *
 * @param name service name
 */
public AbstractYarnScheduler(String name) {
  super(name);
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.maxAllocReadLock = lock.readLock();
  this.maxAllocWriteLock = lock.writeLock();
}
 
源代码5 项目: big-c   文件: RMContainerImpl.java
public RMContainerImpl(Container container,
    ApplicationAttemptId appAttemptId, NodeId nodeId,
    String user, RMContext rmContext, long creationTime) {
  this.stateMachine = stateMachineFactory.make(this);
  this.containerId = container.getId();
  this.nodeId = nodeId;
  this.container = container;
  this.appAttemptId = appAttemptId;
  this.user = user;
  this.creationTime = creationTime;
  this.rmContext = rmContext;
  this.eventHandler = rmContext.getDispatcher().getEventHandler();
  this.containerAllocationExpirer = rmContext.getContainerAllocationExpirer();
  this.isAMContainer = false;
  this.resourceRequests  = null;
  this.resumeOpportunity = 0;
  
  this.utilization = 1;
  this.suspendTime = new LinkedList<Long>();
  this.resumeTime  = new LinkedList<Long>();

  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();
  
  this.PR_NUMBER=rmContext.getYarnConfiguration().getInt(
  		"yarn.resourcemanager.monitor.capacity.preemption.pr_number", 2);
  		

  rmContext.getRMApplicationHistoryWriter().containerStarted(this);
  rmContext.getSystemMetricsPublisher().containerCreated(
      this, this.creationTime);
}
 
源代码6 项目: moleculer-java   文件: DefaultEventbus.java
public DefaultEventbus(boolean asyncLocalInvocation) {

		// Async or direct local invocation
		this.asyncLocalInvocation = asyncLocalInvocation;

		// Init locks
		ReentrantReadWriteLock registryLock = new ReentrantReadWriteLock(true);
		registryReadLock = registryLock.readLock();
		registryWriteLock = registryLock.writeLock();

		ReentrantReadWriteLock requestStreamLock = new ReentrantReadWriteLock(false);
		requestStreamReadLock = requestStreamLock.readLock();
		requestStreamWriteLock = requestStreamLock.writeLock();
	}
 
源代码7 项目: hadoop   文件: ResourceUsage.java
public ResourceUsage() {
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  readLock = lock.readLock();
  writeLock = lock.writeLock();

  usages = new HashMap<String, UsageByLabel>();
  usages.put(NL, new UsageByLabel(NL));
}
 
源代码8 项目: alfresco-core   文件: PathMapper.java
/**
 * Default constructor
 */
public PathMapper()
{
    ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    readLock = lock.readLock();
    writeLock = lock.writeLock();
    
    pathMaps = new HashMap<String, Set<String>>(37);
    derivedPathMaps = new HashMap<String, Set<String>>(127);
    derivedPathMapsPartial = new HashMap<String, Set<String>>(127);
}
 
源代码9 项目: hadoop   文件: AbstractYarnScheduler.java
/**
 * Construct the service.
 *
 * @param name service name
 */
public AbstractYarnScheduler(String name) {
  super(name);
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.maxAllocReadLock = lock.readLock();
  this.maxAllocWriteLock = lock.writeLock();
}
 
源代码10 项目: alfresco-repository   文件: ValueProtectingMap.java
/**
 * Construct providing a protected map, complementing the set of
 * {@link #DEFAULT_IMMUTABLE_CLASSES default immutable classes}
 * 
 * @param protectedMap          the map to safeguard
 * @param immutableClasses      additional immutable classes
 *                              over and above the {@link #DEFAULT_IMMUTABLE_CLASSES default set}
 *                              (may be <tt>null</tt>
 */
public ValueProtectingMap(Map<K, V> protectedMap, Set<Class<?>> immutableClasses)
{
    // Unwrap any internal maps if given a value protecting map
    if (protectedMap instanceof ValueProtectingMap)
    {
        ValueProtectingMap<K, V> mapTemp = (ValueProtectingMap<K, V>) protectedMap;
        this.map = mapTemp.map;
    }
    else
    {
        this.map = protectedMap;
    }
    
    this.cloned = false;
    if (immutableClasses == null)
    {
        this.immutableClasses = Collections.emptySet();
    }
    else
    {
        this.immutableClasses = new HashSet<Class<?>>(immutableClasses);
    }
    // Construct locks
    ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    this.readLock = lock.readLock();
    this.writeLock = lock.writeLock();
}
 
源代码11 项目: neoscada   文件: AbstractDataSourceHandler.java
public AbstractDataSourceHandler ( final ObjectPoolTracker<DataSource> poolTracker )
{
    this.poolTracker = poolTracker;
    this.serviceListener = new ServiceListener () {

        @Override
        public void dataSourceChanged ( final DataSource dataSource )
        {
            AbstractDataSourceHandler.this.setDataSource ( dataSource );
        }
    };

    this.dataSourceListener = new DataSourceListener () {

        @Override
        public void stateChanged ( final DataItemValue value )
        {
            AbstractDataSourceHandler.this.stateChanged ( value );
        }
    };

    final ReentrantReadWriteLock lock = new ReentrantReadWriteLock ();
    this.dataSourceReadLock = lock.readLock ();
    this.dataSourceWriteLock = lock.writeLock ();

    this.trackerLock = new ReentrantLock ();
}
 
源代码12 项目: hbase   文件: FileArchiverNotifierImpl.java
public FileArchiverNotifierImpl(
    Connection conn, Configuration conf, FileSystem fs, TableName tn) {
  this.conn = conn;
  this.conf = conf;
  this.fs = fs;
  this.tn = tn;
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  readLock = lock.readLock();
  writeLock = lock.writeLock();
}
 
源代码13 项目: hadoop   文件: ApplicationImpl.java
public ApplicationImpl(Dispatcher dispatcher, String user, ApplicationId appId,
    Credentials credentials, Context context) {
  this.dispatcher = dispatcher;
  this.user = user;
  this.appId = appId;
  this.credentials = credentials;
  this.aclsManager = context.getApplicationACLsManager();
  this.context = context;
  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  readLock = lock.readLock();
  writeLock = lock.writeLock();
  stateMachine = stateMachineFactory.make(this);
}
 
源代码14 项目: aws-sdk-java-v2   文件: FifoCache.java
/**
 * @param maxSize
 *            the maximum number of entries of the cache
 */
public FifoCache(final int maxSize) {
    if (maxSize < 1) {
        throw new IllegalArgumentException("maxSize " + maxSize
                                           + " must be at least 1");
    }
    map = new BoundedLinkedHashMap<>(maxSize);
    ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    rlock = lock.readLock();
    wlock = lock.writeLock();
}
 
源代码15 项目: hadoop   文件: RMAppImpl.java
public RMAppImpl(ApplicationId applicationId, RMContext rmContext,
    Configuration config, String name, String user, String queue,
    ApplicationSubmissionContext submissionContext, YarnScheduler scheduler,
    ApplicationMasterService masterService, long submitTime,
    String applicationType, Set<String> applicationTags, 
    ResourceRequest amReq) {

  this.systemClock = new SystemClock();

  this.applicationId = applicationId;
  this.name = name;
  this.rmContext = rmContext;
  this.dispatcher = rmContext.getDispatcher();
  this.handler = dispatcher.getEventHandler();
  this.conf = config;
  this.user = user;
  this.queue = queue;
  this.submissionContext = submissionContext;
  this.scheduler = scheduler;
  this.masterService = masterService;
  this.submitTime = submitTime;
  this.startTime = this.systemClock.getTime();
  this.applicationType = applicationType;
  this.applicationTags = applicationTags;
  this.amReq = amReq;

  int globalMaxAppAttempts = conf.getInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS,
      YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS);
  int individualMaxAppAttempts = submissionContext.getMaxAppAttempts();
  if (individualMaxAppAttempts <= 0 ||
      individualMaxAppAttempts > globalMaxAppAttempts) {
    this.maxAppAttempts = globalMaxAppAttempts;
    LOG.warn("The specific max attempts: " + individualMaxAppAttempts
        + " for application: " + applicationId.getId()
        + " is invalid, because it is out of the range [1, "
        + globalMaxAppAttempts + "]. Use the global max attempts instead.");
  } else {
    this.maxAppAttempts = individualMaxAppAttempts;
  }

  this.attemptFailuresValidityInterval =
      submissionContext.getAttemptFailuresValidityInterval();
  if (this.attemptFailuresValidityInterval > 0) {
    LOG.info("The attemptFailuresValidityInterval for the application: "
        + this.applicationId + " is " + this.attemptFailuresValidityInterval
        + ".");
  }

  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();

  this.stateMachine = stateMachineFactory.make(this);

  rmContext.getRMApplicationHistoryWriter().applicationStarted(this);
  rmContext.getSystemMetricsPublisher().appCreated(this, startTime);
}
 
源代码16 项目: Tomcat7.0.67   文件: SocketWrapper.java
public SocketWrapper(E socket) {
    this.socket = socket;
    ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    this.blockingStatusReadLock = lock.readLock();
    this.blockingStatusWriteLock =lock.writeLock();
}
 
源代码17 项目: pulsar   文件: UnAckedMessageTracker.java
public UnAckedMessageTracker(PulsarClientImpl client, ConsumerBase<?> consumerBase, long ackTimeoutMillis, long tickDurationInMs) {
    Preconditions.checkArgument(tickDurationInMs > 0 && ackTimeoutMillis >= tickDurationInMs);
    this.ackTimeoutMillis = ackTimeoutMillis;
    this.tickDurationInMs = tickDurationInMs;
    ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
    this.readLock = readWriteLock.readLock();
    this.writeLock = readWriteLock.writeLock();
    this.messageIdPartitionMap = new ConcurrentHashMap<>();
    this.timePartitions = new ArrayDeque<>();

    int blankPartitions = (int)Math.ceil((double)this.ackTimeoutMillis / this.tickDurationInMs);
    for (int i = 0; i < blankPartitions + 1; i++) {
        timePartitions.add(new ConcurrentOpenHashSet<>(16, 1));
    }

    timeout = client.timer().newTimeout(new TimerTask() {
        @Override
        public void run(Timeout t) throws Exception {
            Set<MessageId> messageIds = TL_MESSAGE_IDS_SET.get();
            messageIds.clear();

            writeLock.lock();
            try {
                ConcurrentOpenHashSet<MessageId> headPartition = timePartitions.removeFirst();
                if (!headPartition.isEmpty()) {
                    log.warn("[{}] {} messages have timed-out", consumerBase, headPartition.size());
                    headPartition.forEach(messageId -> {
                        addChunkedMessageIdsAndRemoveFromSequnceMap(messageId, messageIds, consumerBase);
                        messageIds.add(messageId);
                        messageIdPartitionMap.remove(messageId);
                    });
                }

                headPartition.clear();
                timePartitions.addLast(headPartition);
            } finally {
                if (messageIds.size() > 0) {
                    consumerBase.onAckTimeoutSend(messageIds);
                    consumerBase.redeliverUnacknowledgedMessages(messageIds);
                }
                timeout = client.timer().newTimeout(this, tickDurationInMs, TimeUnit.MILLISECONDS);
                writeLock.unlock();
            }
        }
    }, this.tickDurationInMs, TimeUnit.MILLISECONDS);
}
 
源代码18 项目: tez   文件: TaskAttemptImpl.java
@SuppressWarnings("rawtypes")
public TaskAttemptImpl(TezTaskAttemptID attemptId, EventHandler eventHandler,
    TaskCommunicatorManagerInterface taskCommunicatorManagerInterface, Configuration conf, Clock clock,
    TaskHeartbeatHandler taskHeartbeatHandler, AppContext appContext,
    boolean isRescheduled,
    Resource resource, ContainerContext containerContext, boolean leafVertex,
    Task task, TaskLocationHint locationHint, TaskSpec taskSpec,
    TezTaskAttemptID schedulingCausalTA) {

  ReentrantReadWriteLock rwLock = new ReentrantReadWriteLock();
  this.readLock = rwLock.readLock();
  this.writeLock = rwLock.writeLock();
  this.attemptId = attemptId;
  this.eventHandler = eventHandler;
  //Reported status
  this.conf = conf;
  this.clock = clock;
  this.taskHeartbeatHandler = taskHeartbeatHandler;
  this.appContext = appContext;
  this.vertex = task.getVertex();
  this.task = task;
  this.locationHint = locationHint;
  this.taskSpec = taskSpec;
  this.creationCausalTA = schedulingCausalTA;
  this.creationTime = clock.getTime();

  this.reportedStatus = new TaskAttemptStatus(this.attemptId);
  initTaskAttemptStatus(reportedStatus);
  RackResolver.init(conf);
  this.stateMachine = stateMachineFactory.make(this);
  this.isRescheduled = isRescheduled;
  this.taskResource = resource;
  this.containerContext = containerContext;
  this.leafVertex = leafVertex;
  this.hungIntervalMax = conf.getLong(
      TezConfiguration.TEZ_TASK_PROGRESS_STUCK_INTERVAL_MS, 
      TezConfiguration.TEZ_TASK_PROGRESS_STUCK_INTERVAL_MS_DEFAULT);

  this.recoveryData = appContext.getDAGRecoveryData() == null ?
      null : appContext.getDAGRecoveryData().getTaskAttemptRecoveryData(attemptId);
}
 
public RealtimeInvertedIndexReader() {
  ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  _readLock = readWriteLock.readLock();
  _writeLock = readWriteLock.writeLock();
}
 
源代码20 项目: big-c   文件: RMAppImpl.java
public RMAppImpl(ApplicationId applicationId, RMContext rmContext,
    Configuration config, String name, String user, String queue,
    ApplicationSubmissionContext submissionContext, YarnScheduler scheduler,
    ApplicationMasterService masterService, long submitTime,
    String applicationType, Set<String> applicationTags, 
    ResourceRequest amReq) {

  this.systemClock = new SystemClock();

  this.applicationId = applicationId;
  this.name = name;
  this.rmContext = rmContext;
  this.dispatcher = rmContext.getDispatcher();
  this.handler = dispatcher.getEventHandler();
  this.conf = config;
  this.user = user;
  this.queue = queue;
  this.submissionContext = submissionContext;
  this.scheduler = scheduler;
  this.masterService = masterService;
  this.submitTime = submitTime;
  this.startTime = this.systemClock.getTime();
  this.applicationType = applicationType;
  this.applicationTags = applicationTags;
  this.amReq = amReq;

  int globalMaxAppAttempts = conf.getInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS,
      YarnConfiguration.DEFAULT_RM_AM_MAX_ATTEMPTS);
  int individualMaxAppAttempts = submissionContext.getMaxAppAttempts();
  if (individualMaxAppAttempts <= 0 ||
      individualMaxAppAttempts > globalMaxAppAttempts) {
    this.maxAppAttempts = globalMaxAppAttempts;
    LOG.warn("The specific max attempts: " + individualMaxAppAttempts
        + " for application: " + applicationId.getId()
        + " is invalid, because it is out of the range [1, "
        + globalMaxAppAttempts + "]. Use the global max attempts instead.");
  } else {
    this.maxAppAttempts = individualMaxAppAttempts;
  }

  this.attemptFailuresValidityInterval =
      submissionContext.getAttemptFailuresValidityInterval();
  if (this.attemptFailuresValidityInterval > 0) {
    LOG.info("The attemptFailuresValidityInterval for the application: "
        + this.applicationId + " is " + this.attemptFailuresValidityInterval
        + ".");
  }

  ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
  this.readLock = lock.readLock();
  this.writeLock = lock.writeLock();

  this.stateMachine = stateMachineFactory.make(this);

  rmContext.getRMApplicationHistoryWriter().applicationStarted(this);
  rmContext.getSystemMetricsPublisher().appCreated(this, startTime);
}
 
源代码评论
动弹
沙发等你来抢