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

查看:284
本文介绍了MySQL Connector / 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 Connector / JDBC线程安全吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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