MySQL 连接器/JDBC 线程安全吗? [英] Is MySQL Connector/JDBC thread safe?

查看:36
本文介绍了MySQL 连接器/JDBC 线程安全吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标准的 MySQL JDBC 驱动程序线程安全吗?具体来说,我想在所有线程中使用单个连接,但每个语句只会在单个线程中使用.是否有某些情况是安全的,而另一些则不安全?您在这里有什么体验?

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. Are there certain scenarios that are safe and others that aren't? What's your experience here?

推荐答案

每个连接开始/提交事务.除非您正在做一些非常具体的事情(老实说,我真的想不出一个例子来证明这是合理的),否则最好使用连接池和每个线程的连接.

Transactions are started / committed per connection. Unless you're doing some very specific stuff (I can't really think of an example where that would be justified to be honest), you're better off with a connection pool and connection per thread.

这篇关于MySQL 连接器/JDBC 线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆