开发者

Is a MySql connection with Broken Pipe or EOFException = null?

开发者 https://www.devze.com 2023-03-18 17:07 出处:网络
Just curious, does a MySql connection with Broken Pipe or EOFException = null? I\'m asking cause it might be causing a logic error in my code. Or is there a way to simulate the broken pipe or eof fas

Just curious, does a MySql connection with Broken Pipe or EOFException = null?

I'm asking cause it might be causing a logic error in my code. Or is there a way to simulate the broken pipe or eof faster? Currently I'm doing database pooling and I do a ch开发者_StackOverfloweck where is the conn !=null, counter++ to keep track of the number of connections in use, but if the above is true, I will do a counter++ when the connection is not valid because it does not actually return a null but an object that is not valid. Hope this makes sense.


Regardless of whether the connection is still valid or not, the no reference to the connection instance will be == to null, unless it is actually null. This is entirely unrelated to whether the connection instance is in a usable state.

A common method to determine the latter is to send a simple query through the connection, after it has been dormant for a while. Depending on your database, it could be as simple as „SELECT 1“


There is not really enough context to answer your question. (Hint: post the actual code!!)

However, in general an unexpected null will result in a NullPointerException, and not some subclass of IOException.

0

精彩评论

暂无评论...
验证码 换一张
取 消