File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -506,6 +506,23 @@ private static Object doUnbindResource(Object actualKey) {
506506
507507同时注意getTransaction方法返回的是一个TransactionStatus对象,** 被挂起的事务的各种状态都被保存在此对象中** 。
508508
509+ 那么挂起这个操作到底是如何实现(起作用)的呢?
510+
511+ DataSourceTransactionManager.doSuspend:
512+
513+ ``` java
514+ @Override
515+ protected Object doSuspend(Object transaction) {
516+ DataSourceTransactionObject txObject = (DataSourceTransactionObject ) transaction;
517+ txObject. setConnectionHolder(null );
518+ ConnectionHolder conHolder = (ConnectionHolder )
519+ TransactionSynchronizationManager . unbindResource(this . dataSource);
520+ return conHolder;
521+ }
522+ ```
523+
524+ 其实玄机就在于将ConnectionHolder设为null这一行,因为** 一个ConnectionHolder对象就代表了一个数据库连接,将ConnectionHolder设为null就意味着我们下次要使用连接时,将重新从连接池获取,而新的连接的自动提交是为true的** 。
525+
509526##### PROPAGATION_REQUIRES_NEW
510527
511528``` java
You can’t perform that action at this time.
0 commit comments