在此link ,作者指出:
"After this change the storage the engine used by the sequence table can be MyISAM or INNODB since the sequences are allocated using a new connection without being affected by any other transactions that might be in progress. ".
为什么我们应该创建一个新连接来启动事务?我认为,如果一个连接不是同时由两个线程持有,则该连接上不会有“其他事务”。一个连接可以同时被两个线程处理吗?
最佳答案
Why should we create a new connection to start a transaction?
因为没有办法解决这个问题。您必须先与数据库建立连接,然后才能查询数据库。
Could one connection behold by two threads at the same time?
是的,它could 。特别是如果两个线程正在操作不同的表。为什么不重用现有的连接呢?在更现代的框架中,您会发现连接池有一个可供任何线程使用的开放连接池。拥有连接池是更好的做法。
关于java - spring-jdbc中一个连接可以同时被两个线程持有吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57946683/