如果有多个线程要插入到MySQL,是否需要同步?

时间:2022-08-24 04:19:45

I'll be using a multi-threaded Java program to insert new records to a table in MySQL. Is it necessary to synchronize for this? Or is it OK since each insert is a different record in my case?

我将使用一个多线程Java程序将新记录插入到MySQL的表中。是否需要为此进行同步?或者因为在我的例子中,每个插入都是不同的记录,所以可以吗?

1 个解决方案

#1


6  

The database driver will do this for you under the covers, if it is necessary. You should assume that the database can handle concurrent CRUD access.

如果有必要,数据库驱动程序将在幕后为您做这些工作。您应该假设数据库可以处理并发的CRUD访问。

The drivers I've used for SQLServer and Sybase have always locked the Connection object, although you could be using multiple connections via a pool of course!

我为SQLServer和Sybase使用的驱动程序总是锁定连接对象,尽管您可以通过一个池使用多个连接!

#1


6  

The database driver will do this for you under the covers, if it is necessary. You should assume that the database can handle concurrent CRUD access.

如果有必要,数据库驱动程序将在幕后为您做这些工作。您应该假设数据库可以处理并发的CRUD访问。

The drivers I've used for SQLServer and Sybase have always locked the Connection object, although you could be using multiple connections via a pool of course!

我为SQLServer和Sybase使用的驱动程序总是锁定连接对象,尽管您可以通过一个池使用多个连接!