在 spring-jdbc 中是否可以同时由两个线程保持一个连接?

Does one connection could be hold by two thread at the same time in spring-jdbc?

在此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. ".

为什么我们要创建一个新的连接来启动一个事务?我认为如果一个连接不是同时被两个线程持有,那么这个连接上就不会有'other transaction'。一个连接可以同时被两个线程看到吗?

Why should we create a new connection to start a transaction?

因为没有办法绕过它。您必须先与数据库建立连接,然后才能查询数据库。

Could one connection behold by two threads at the same time?

是的,它 could。特别是如果两个线程正在使用不同的表进行操作。为什么不重用现有连接?在更现代的框架中,你会发现连接池有一个开放的连接池,任何线程都可以使用它。最好有一个连接池。