0
我在下面粘贴了我的代码。在我们的应用程序中,他们在线程本地设置事务。
其实我的疑问是为什么我们需要这个?
如果我们没有在threadlocal中设置tranaction会发生什么?我们是否真的需要在ThreadLocal中设置事务?
public void beginTransaction() {
final String METHOD_NAME = "beginTransaction";
log.entering(CLASS_NAME, METHOD_NAME);
PcUtilLogging.logTransactionLifecycle("Begin Transaction",
this.persistenceConfigurationKey);
// Initialize.
final PcRequestContext context = PcRequestContext.getInstance();
final PersistenceManager pm =
context.getPersistenceManager(this.persistenceConfigurationKey);
try {
// Begin a new transaction.
final Transaction transaction = pm.newTransaction();
// Set the Transaction in ThreadLocal.
context.setTransaction(this.persistenceConfigurationKey,
transaction);
} catch (final Exception e) {
// Throw.
throw new PcTransactionException(
new ApplicationExceptionAttributes.Builder(CLASS_NAME, METHOD_NAME).build(),
"Error encountered while attempting to begin a ["
+ this.getPersistenceConfigurationKey()
+ "] transaction.", e);
}
log.exiting(CLASS_NAME, METHOD_NAME);
return;
}
thanks @augusto –