IS ResultSet线程安全 [英] IS ResultSet thread safe

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

问题描述

ResultSet线程安全吗?

Is ResultSet Thread safe?

出现我的问题是因为在我的程序中我为每个查询使用了不同的语句,我已将ResultSet声明为局部变量,但它给我一个ResultSet关闭后不允许的操作错误.但是我的语句正在工作,因为我正在使用插入和删除查询中的语句.我已经注释了ResultSet部分并且没有收到错误消息!

My question arises because in my program i have used different statement for each query i have declared a ResultSet as an local variable but it gives me a error of Operation not allowed after ResultSet is closed. But my statements are working as i'm using the statements in insert and delete query.I have commented the ResultSet part and have not got the error !!

推荐答案

真正的问题是您正在多个线程之间共享Statement对象.每次执行"一条语句时,先前返回的ResultSet都会自动关闭.在这种情况下,ResultSet对象属于"可能尚未完成使用的另一个线程.因此,例外...

The real problem is that you are sharing Statement objects between multiple threads. Each time you "execute" a Statement, the previously returned ResultSet is automatically closed. In this case, the ResultSet objects "belong" to a different thread which may not yet have finished using it. Hence the exception ...

您不应在多个线程之间共享Connection,Statement/PreparedStatement或ResultSet对象.每个线程都应获取并释放自己的资源.

You should not share Connection, Statement / PreparedStatement or ResultSet objects between multiple threads. Each thread should acquire and release its own resources.

这篇关于IS ResultSet线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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