Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do MySQL Connections close automatically when the program exits? [duplicate]

If I create a MySQL Connection in my java program, and the program exits from main method, what happens to this MySQL Connection?

public static void main(String args[])
{
    Connection conn = getConnection(...);

    return;    
}

Does this connection get closed automatically?

Or does the connection stays alive until it times out?

like image 489
SHH Avatar asked Dec 03 '25 12:12

SHH


1 Answers

The operating system will either close or reset all open TCP connections of a process when the process exits, depending on the platform. In either event the database server will notice immediately. No timeout.

like image 166
user207421 Avatar answered Dec 06 '25 02:12

user207421



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!