Will sql connections automatically close if we close the JVM?

I created a test program that creates 20 threads, and then these threads will open many sql connections. Suppose you are running this program from eclipse, and now if you close eclipse. Will this close all open sql connections? If not, what will happen to them? Will 100 open connections be shown on the database side? If so, what to do in this case?

+3
source share
2 answers

Connections will not be closed as during a call java.sql.Connection.close(). Basically, the JVM that opened the connection cannot support TCP / IP connections in the database. They will be immediately disabled. Consequently, the “connection” will also be closed. The database, however, may not respond immediately and maintain its sessions for some time.

In Oracle, you can kill sessions in the database directly if you have sufficient privileges.

I assume that the behavior is vendor specific and / or configuration specific. There is no general answer.

+5
source

, jdbc, . , , . , - . :

  • , db.
  • finalize() . , - , , , .
  • hookdown, JVM, . , JVM ( kill -9 unix).

, , . 100 .

0

Source: https://habr.com/ru/post/1781783/


All Articles