Is MySQL Connector/JDBC thread safe?

前端 未结 3 619
花落未央
花落未央 2020-12-10 03:16

Is the standard MySQL JDBC driver thread-safe? Specifically I want to use a single connection across all threads, but each statement will only be used in a single thread. Ar

3条回答
  •  旧时难觅i
    2020-12-10 03:45

    If autocommit = 1, then it is very feasible to have multiple threads share the same connection, provided the access to the connection is synchronized. If autocommit = 0, you will have to control access to the connection via some sort of mutex until the commit happens.

    Unless you absolutely are limited in the amount of connections your application can have, a connection pool may be a more viable alternative.

提交回复
热议问题