Is MySQL Connector/JDBC thread safe?

前端 未结 3 614
花落未央
花落未央 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条回答
  •  再見小時候
    2020-12-10 03:36

    Based on my recent experience, Connection object is not thread safe in Connector/J 5.1.33.

    I've ran into a deadlock situation described in bug 67760. Not sure if it is a bug, but one reasonable advice from the discussion was:

    [12 Dec 2012 20:33] Todd Farmer

    Please do not use a single Connection object across multiple threads without proper synchronization. Connector/J - and more importantly, the MySQL client-server protocol - does not allow for concurrent operations using the same Connection object. If a Connection object must be shared across threads, it is the responsibility of the application code author to ensure operations are properly serialized.

提交回复
热议问题