How does JDBC manage database connectivity internally, and what are the best practices for preventing resource leaks in a multi-threaded application?