Will the sql connections automatically get closed if we close the JVM?

前端 未结 2 1595
忘了有多久
忘了有多久 2021-01-13 04:55

I created a test program which creates 20 threads and then these threads will open many sql connection. Lets say you are executing this program from eclipse and now if you w

2条回答
  •  迷失自我
    2021-01-13 05:53

    The connections won't close as in calling java.sql.Connection.close(). Basically, the JVM that opened the connection can not keep the TCP/IP connections to the database alive. These will be shut down immediately. Hence, the "connection" will be shut down as well. The database, however, may not react immediately to this and keep its sessions alive for a while.

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

    I guess, the behaviour is vendor-specific and/or configuration-specific. There is no general answer.

提交回复
热议问题