简体   繁体   中英

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

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 check 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.

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 .

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“

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM