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


Java Lock.lock方法代码示例

本文整理汇总了Java中java.util.concurrent.locks.Lock.lock方法的典型用法代码示例。如果您正苦于以下问题:Java Lock.lock方法的具体用法?Java Lock.lock怎么用?Java Lock.lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.locks.Lock的用法示例。


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

示例1: statusSolutionInfo

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
@Override
public Map<String,String> statusSolutionInfo() {
	if (isPassivated())
		return (iBestSolutionInfoBeforePassivation == null ? iCurrentSolutionInfoBeforePassivation : iBestSolutionInfoBeforePassivation);
    Lock lock = currentSolution().getLock().readLock();
    lock.lock();
    try {
		Map<String,String> info = super.currentSolution().getBestInfo();
		try {
			Solution<V, T> solution = getWorkingSolution();
			if (info == null || getSolutionComparator().isBetterThanBestSolution(solution))
				info = solution.getModel().getInfo(solution.getAssignment());
		} catch (ConcurrentModificationException e) {}
		return info;
    } finally {
    	lock.unlock();
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:19,代码来源:AbstractSolver.java

示例2: getAssignedExams

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
@Override
public Collection<ExamAssignmentInfo> getAssignedExams(Long subjectAreaId) {
    if (subjectAreaId==null || subjectAreaId<0) return getAssignedExams();
    String sa = new SubjectAreaDAO().get(subjectAreaId).getSubjectAreaAbbreviation()+" ";
    Lock lock = currentSolution().getLock().readLock();
    lock.lock();
    try {
        Vector<ExamAssignmentInfo> ret = new Vector<ExamAssignmentInfo>();
        for (Exam exam: currentSolution().getModel().variables()) {
            boolean hasSubjectArea = false;
            for (Iterator<ExamOwner> f=exam.getOwners().iterator();!hasSubjectArea && f.hasNext();) {
                ExamOwner ecs = (ExamOwner)f.next();
                hasSubjectArea = ecs.getName().startsWith(sa);
            }
            if (hasSubjectArea) {
            	ExamPlacement placement = currentSolution().getAssignment().getValue(exam);
            	if (placement!=null)
            		ret.add(new ExamAssignmentInfo(placement, currentSolution().getAssignment()));
            }
        }
        return ret;
    } finally {
    	lock.unlock();
    }
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:26,代码来源:ExamSolver.java

示例3: getAssignmentInfo

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
@Override
  public AssignmentPreferenceInfo getAssignmentInfo(Long classId) {
  	Lock lock = currentSolution().getLock().readLock();
lock.lock();
try {
  		Lecture lecture = null;
  		for (Lecture l: currentSolution().getModel().variables()) {
  			if (l.getClassId().equals(classId)) {
  				lecture = l; break;
  			}
  		}
  		if (lecture==null) return null;
  		Placement placement = (Placement)currentSolution().getAssignment().getValue(lecture);
  		if (placement==null) return null;
  		return new AssignmentPreferenceInfo(this,placement);
  	} finally {
  		lock.unlock();
  	}
  }
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:20,代码来源:TimetableSolver.java

示例4: getChangesToBest

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
@Override
public Vector getChangesToBest() {
	Vector ret = new Vector();
	Lock lock = currentSolution().getLock().readLock();
	lock.lock();
	try {
		for (Lecture lecture: currentSolution().getModel().variables()) {
			Placement placement = currentSolution().getAssignment().getValue(lecture);
			if (!ToolBox.equals(lecture.getBestAssignment(), placement)) {
				RecordedAssignment a = new RecordedAssignment(this,(Placement)lecture.getBestAssignment(),placement);
				if (lecture.getBestAssignment()!=null) {
					a.getBefore().setDetails(new ClassAssignmentDetails(this,lecture,(Placement)lecture.getBestAssignment(),false));
				}
				if (placement!=null) {
					a.getAfter().setDetails(new ClassAssignmentDetails(this,lecture,false));
				}
				ret.addElement(a);
			}
		}
	} finally {
		lock.unlock();
	}
	return ret;
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:25,代码来源:TimetableSolver.java

示例5: getJsapiTicket

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
@Override
public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
  Lock lock = this.wxMpConfigStorage.getJsapiTicketLock();
  try {
    lock.lock();

    if (forceRefresh) {
      this.wxMpConfigStorage.expireJsapiTicket();
    }

    if (this.wxMpConfigStorage.isJsapiTicketExpired()) {
      String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
      String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
      JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
      JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
      String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
      int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
      this.wxMpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds);
    }
  } finally {
    lock.unlock();
  }
  return this.wxMpConfigStorage.getJsapiTicket();
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:25,代码来源:WxMpServiceImpl.java

示例6: getRealmInternal

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
protected Realm getRealmInternal() {
    Lock l = realmLock.readLock();
    try {
        l.lock();
        return realm;
    } finally {
        l.unlock();
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:10,代码来源:ContainerBase.java

示例7: getSignature

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
/**
 * The set of parameters for this operation.
 */
public ParameterInfo[] getSignature() {
    Lock readLock = parametersLock.readLock();
    try {
        readLock.lock();
        return this.parameters;
    } finally {
        readLock.unlock();
    }
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:13,代码来源:OperationInfo.java

示例8: getSuggestions

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
@Override
public ExamSuggestionsInfo getSuggestions(long examId, ExamProposedChange change, String filter, int depth, int limit, long timeOut) {
	Lock lock = currentSolution().getLock().writeLock();
	lock.lock();
    try {
        Exam exam = getExam(examId);
        if (exam==null) return null;
        ExamSuggestions s = new ExamSuggestions(this);
        s.setDepth(depth);
        s.setFilter(filter);
        s.setLimit(limit);
        s.setTimeOut(timeOut);
        TreeSet<ExamProposedChange> suggestions = s.computeSuggestions(exam, (change==null?null:change.getAssignments()));
        String message = null;
        if (s.wasTimeoutReached()) {
            message = "("+(timeOut/1000l)+"s timeout reached, "+s.getNrCombinationsConsidered()+" possibilities up to "+depth+" changes were considered, ";
        } else {
            message = "(all "+s.getNrCombinationsConsidered()+" possibilities up to "+depth+" changes were considered, ";
        }
        if (suggestions.isEmpty()) {
            message += "no suggestion found)";
        } else if (s.getNrSolutions()>suggestions.size()) {
            message += "top "+suggestions.size()+" of "+s.getNrSolutions()+" suggestions displayed)";
        } else {
            message += suggestions.size()+" suggestions displayed)";
        }
        return new ExamSuggestionsInfo(suggestions, message, s.wasTimeoutReached());
    } finally {
    	lock.unlock();
    }
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:32,代码来源:ExamSolver.java

示例9: put

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
void put() {
  int randomInt1 = random.nextInt() % 10;
  if (randomInt1 < 0) {
    randomInt1 = randomInt1 * (-1);
  }
  int randomInt2 = random.nextInt() % 100;
  Integer integer1 = Integer.valueOf(randomInt1);
  Integer integer2 = Integer.valueOf(randomInt2);
  Object v = null;
  Object expected = null;
  Lock lock = null;
  if (this.validate) {
    lock = map.get(integer1);
    lock.lock();
  }
  try {
    try {
      v = region1.put(integer1, integer2);
      if (this.validate) {
        expected = region2.put(integer1, integer2);
      }
    } catch (Exception e) {
      exceptionOccuredInPuts = true;
      logWriter.severe("Exception occured in puts ", e);
      fail(" failed during put due to " + e);
    }
  } finally {
    if (lock != null) {
      lock.unlock();
    }
  }
  if (this.validate) {
    if (v != null) {
      assertEquals(expected, v);
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:38,代码来源:ConcurrentRegionOperationsJUnitTest.java

示例10: lockIfExists

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
public static boolean lockIfExists(final Lock lock) {
    if (null == lock) {
        return false;
    }
    lock.lock();
    return true;
}
 
开发者ID:yohlulz,项目名称:MLE5109-Course-samples,代码行数:8,代码来源:LockUtils.java

示例11: getExam

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
public Exam getExam(long examId) {
    Lock lock = currentSolution().getLock().readLock();
    lock.lock();
    try {
        for (Exam exam: currentSolution().getModel().variables()) {
            if (exam.getId()==examId) return exam;
        }
        return null;
    } finally {
    	lock.unlock();
    }
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:13,代码来源:ExamSolver.java

示例12: contains

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
/**
 * Checks whether the store contains an object registered under the given index.
 * 
 * @param index the index to check
 * 
 * @return true if an object is associated with the given index, false if not
 */
public boolean contains(String index) {
    Lock readLock = rwLock.readLock();
    readLock.lock();
    try {
        return objectStore.containsKey(index);
    } finally {
        readLock.unlock();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:IndexingObjectStore.java

示例13: testSingleVMLockUnlock

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
@Test
public void testSingleVMLockUnlock() throws CacheException {
  String name = this.getUniqueName() + "-GLOBAL";
  Region region = getOrCreateRootRegion().createSubregion(name, getGlobalAttrs());

  Lock lock = region.getDistributedLock("obj");
  lock.lock();
  lock.unlock();
}
 
开发者ID:ampool,项目名称:monarch,代码行数:10,代码来源:GlobalLockingDUnitTest.java

示例14: setDescription

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
public void setDescription(String description) {
	Lock l = mBeanInfoLock.writeLock();
	l.lock();
	try {
		this.description = description;
		this.info = null;
	} finally {
		l.unlock();
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:11,代码来源:ManagedBean.java

示例15: delay

import java.util.concurrent.locks.Lock; //导入方法依赖的package包/类
private void delay() {
  final Random random = Utils.random();
  double p = random.nextDouble();
  int mod;
  if (p < 0.9) {
    mod = 0;
  } else if (p < 0.99) {
    mod = 1;
  } else if (p < 0.9999) {
    mod = 2;
  } else {
    mod = 3;
  }
  // this will make mod 3 pauses global
  Lock lock = mod == 3 ? DB_ACCESS.writeLock() : DB_ACCESS.readLock();
  if (mod == 3) {
    System.out.println("OUCH");
  }
  lock.lock();
  try {
    final long baseDelayNs = MICROSECONDS.toNanos(delays[mod]);
    final int delayRangeNs = (int) (MICROSECONDS.toNanos(delays[mod + 1]) - baseDelayNs);
    final long delayNs = baseDelayNs + random.nextInt(delayRangeNs);
    final long deadline = System.nanoTime() + delayNs;
    do {
      LockSupport.parkNanos(deadline - System.nanoTime());
    } while (System.nanoTime() < deadline && !Thread.interrupted());
  } finally {
    lock.unlock();
  }

}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:33,代码来源:GoodBadUglyDB.java


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