java executeupdate,Java线程安全中的executeUpdate方法[通俗易懂]

java executeupdate,Java线程安全中的executeUpdate方法[通俗易懂]IhavemultiplethreadstryingtoupdateaMySQLdatabase?isexecuteUpdatemethodthread-safetouse?解决方案No,itisnotthread-safetouse.Infact,ifsomeotherthreadusesastatement,andthenanot…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

java executeupdate,Java线程安全中的executeUpdate方法[通俗易懂]

I have multiple threads trying to update a MySQL database? is executeUpdate method thread-safe to use?

解决方案

No, it is not thread-safe to use.

In fact, if some other thread uses a statement, and then another thread calls executeUpdate(), then the other thread’s ResultSets, if any, will be closed. JavaDoc for java.sql.Statement (of which PreparedStatement is a subtype) “All execution methods in the Statement interface implicitly close a statment’s current ResultSet object if an open one exists.”

Furthermore, it’s unlikely that a given implementation of executeUpdate() would be written to be mulit-thread safe.

You should either syncrhonize all use of the statement and resulting result sets, or make multiple connections so that each thread uses its own JDBC Connection to the database.. I would recommend the latter.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/179940.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Σ求和符号_西格玛符号怎么打

    Σ求和符号_西格玛符号怎么打转自:https://zh.wikipedia.org/wiki/%E6%B1%82%E5%92%8C%E7%AC%A6%E5%8F%B7求和符号(Σ,sigma),是欧拉于1755年首先使用的。这个符号是源于希腊文σογμαρω(增加)的字头,Σ正是σ的大写。求和的结果是给定的数值相加后的总值,又称加总。举例而言,若有4个数值:1、3、5、7,则这4个数值的总和为:

    2022年10月9日
    2
  • 《JavaScript 模式》读书笔记(4)— 函数5

    这一篇是函数部分的最后一篇。我们来聊聊Curry化。十、Curry这部分我们主要讨论Curry化和部分函数应用的内容。但是在深入讨论之前,我们需要先了解一下函数应用的含义。函数应用在一些纯粹的

    2022年3月25日
    40
  • 在Scala中使用fastJson 解析json字符串

    在Scala中使用fastJson 解析json字符串一 阿里巴巴 FastJson 是一个 Json 处理工具包 包括 序列化 和 反序列化 两部分 它具备如下特征 速度最快 测试表明 fastjson 具有极快的性能 超越任其他的 JavaJsonpars 包括自称最快的 JackJson 功能强大 完全支持 JavaBean 集合 Map 日期 Enum 支持范型 支持自省 无依赖 二 在 Scala 中使用也可使用 fastJson 解析 jso

    2025年9月16日
    2
  • [PHP]程序员技能栈

    [PHP]程序员技能栈

    2021年9月6日
    42
  • Redis-GEO

    Redis-GEO

    2021年11月3日
    48
  • webpack配置文件_pack luggage

    webpack配置文件_pack luggage前言上一篇文章我们使用webpack打包成功了,但是每次都要自己手动输入打包的文件地址和打包到哪里去的地址,非常麻烦,所以这里介绍使用配置文件进行打包webpack.config.js首先我们创

    2022年8月7日
    7

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号