InterviewSolution
| 1. |
In Java, what is a connection leak? How can you fix this? |
|
Answer» If a connection is opened and forgotten about, this is known as a "leak" SINCE each time it occurs, a connection is no longer available for REUSE. Connection leaks occur when some database requests or transactions are not closed properly or are not committed, causing the connections to be abandoned and closed permanently. Java developers commonly experience Connection Leaks when using Connection Pools. In the case where there is a section of code that fails to close a connection properly, a connection will leak from the pool each time the section of code is executed. Eventually, if this SITUATION CONTINUES, the pool will run out of connections, which is known as Pool Exhaustion. The application will hang once all available connections have been leaked. We can fix this by closing the connection and paying particular attention to any error handling code. |
|