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


Java LockTimeoutException类代码示例

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


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

示例1: getTaskToRun

import javax.persistence.LockTimeoutException; //导入依赖的package包/类
@Override
public TaskStatusInfo getTaskToRun(String nodeId) {
	List<TaskStatusInfo> tsi = listTasks(null, toRunTaskStatusFilter, 0, 0);
	if (tsi != null && !tsi.isEmpty()) {
		for (int i = tsi.size() - 1; i >= 0; i--) {
			TaskStatusInfo work = tsi.get(i);
			try {
				em.lock(work, LockModeType.PESSIMISTIC_WRITE);
				if (work.startTaskExecution(nodeId)) {
					return work;
				}
			} catch (LockTimeoutException e) {
				log.fine("Lock exception for task id=" + work.getId());
			}
		}
	}
	return null;
}
 
开发者ID:macanhhuy,项目名称:dcp-api,代码行数:19,代码来源:TaskPersisterJpa.java

示例2: heartbeat

import javax.persistence.LockTimeoutException; //导入依赖的package包/类
@Override
public void heartbeat(String nodeId, Set<String> runningTasksId, long failoverTimeout) {
	List<TaskStatusInfo> tsi = listTasks(null, runningTaskStatusFilter, 0, 0);
	if (tsi != null && !tsi.isEmpty()) {
		long ct = System.currentTimeMillis();
		long ft = ct - failoverTimeout;
		for (TaskStatusInfo task : tsi) {
			try {
				em.lock(task, LockModeType.PESSIMISTIC_WRITE);
				if (task.getTaskStatus() == TaskStatus.RUNNING) {
					if (runningTasksId != null && runningTasksId.contains(task.getId())) {
						task.setHeartbeat(ct);
					} else {
						if (task.getHeartbeat() < ft) {
							changeTaskStatus(task.getId(), TaskStatus.FAILOVER, "Failover necessity detected by node '" + nodeId
									+ "' at " + ct + " due heartbeat timestamp " + task.getHeartbeat());
						}
					}
				}
			} catch (LockTimeoutException e) {
				log.fine("Lock exception for task id=" + task.getId());
			}
		}
	}
}
 
开发者ID:macanhhuy,项目名称:dcp-api,代码行数:26,代码来源:TaskPersisterJpa.java

示例3: getTaskToRun

import javax.persistence.LockTimeoutException; //导入依赖的package包/类
@Override
public TaskStatusInfo getTaskToRun(String nodeId) {
	List<TaskStatusInfo> tsi = listTasks(null, toRunTaskStatusFilter, 0, 0);
	if (tsi != null && !tsi.isEmpty()) {
		for (int i = tsi.size() - 1; i >= 0; i--) {
			TaskStatusInfo work = tsi.get(i);
			if (taskIsRunnableNow(nodeId, work)) {
				try {
					em.lock(work, LockModeType.PESSIMISTIC_WRITE);
					if (work.startTaskExecution(nodeId)) {
						return work;
					}
				} catch (LockTimeoutException e) {
					log.fine("Lock exception for task id=" + work.getId());
				}
			}
		}
	}
	return null;
}
 
开发者ID:searchisko,项目名称:searchisko,代码行数:21,代码来源:TaskPersisterJpa.java

示例4: convertJpaAccessExceptionIfPossible

import javax.persistence.LockTimeoutException; //导入依赖的package包/类
/**
 * Convert the given runtime exception to an appropriate exception from the
 * {@code org.springframework.dao} hierarchy.
 * Return null if no translation is appropriate: any other exception may
 * have resulted from user code, and should not be translated.
 * <p>The most important cases like object not found or optimistic locking failure
 * are covered here. For more fine-granular conversion, JpaTransactionManager etc
 * support sophisticated translation of exceptions via a JpaDialect.
 * @param ex runtime exception that occurred
 * @return the corresponding DataAccessException instance,
 * or {@code null} if the exception should not be translated
 */
public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) {
	// Following the JPA specification, a persistence provider can also
	// throw these two exceptions, besides PersistenceException.
	if (ex instanceof IllegalStateException) {
		return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
	}
	if (ex instanceof IllegalArgumentException) {
		return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
	}

	// Check for well-known PersistenceException subclasses.
	if (ex instanceof EntityNotFoundException) {
		return new JpaObjectRetrievalFailureException((EntityNotFoundException) ex);
	}
	if (ex instanceof NoResultException) {
		return new EmptyResultDataAccessException(ex.getMessage(), 1, ex);
	}
	if (ex instanceof NonUniqueResultException) {
		return new IncorrectResultSizeDataAccessException(ex.getMessage(), 1, ex);
	}
	if (ex instanceof QueryTimeoutException) {
		return new org.springframework.dao.QueryTimeoutException(ex.getMessage(), ex);
	}
	if (ex instanceof LockTimeoutException) {
		return new CannotAcquireLockException(ex.getMessage(), ex);
	}
	if (ex instanceof PessimisticLockException) {
		return new PessimisticLockingFailureException(ex.getMessage(), ex);
	}
	if (ex instanceof OptimisticLockException) {
		return new JpaOptimisticLockingFailureException((OptimisticLockException) ex);
	}
	if (ex instanceof EntityExistsException) {
		return new DataIntegrityViolationException(ex.getMessage(), ex);
	}
	if (ex instanceof TransactionRequiredException) {
		return new InvalidDataAccessApiUsageException(ex.getMessage(), ex);
	}

	// If we have another kind of PersistenceException, throw it.
	if (ex instanceof PersistenceException) {
		return new JpaSystemException((PersistenceException) ex);
	}

	// If we get here, we have an exception that resulted from user code,
	// rather than the persistence provider, so we return null to indicate
	// that translation should not occur.
	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:62,代码来源:EntityManagerFactoryUtils.java


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