cancel
Showing results for 
Search instead for 
Did you mean: 
Community Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

threads leakage when getConnection fails

olegmir
New Contributor III

Hi,

we are using databricks jdbc https://mvnrepository.com/artifact/com.databricks/databricks-jdbc/2.6.33

it seems like there is a thread leakage when getConnection fails

could anyone advice?

can be reproduced with

    @Test
    void databricksThreads() {
        while(true) {
            String server = "put_you_server_here";
            String url = "jdbc:databricks://" + server + ":443;HttpPath=dummy_path;TransportMode=http;";

            DataSource dataSource = new DataSource();
            dataSource.setURL(url);

            try (Connection connection = dataSource.getConnection()){

            } catch (Exception e) {
                System.out.println("ManagementFactory.getThreadMXBean().getThreadCount() " + ManagementFactory.getThreadMXBean().getThreadCount());
            }
        }
    }

///////

ManagementFactory.getThreadMXBean().getThreadCount() 582
ManagementFactory.getThreadMXBean().getThreadCount() 583
ManagementFactory.getThreadMXBean().getThreadCount() 584
ManagementFactory.getThreadMXBean().getThreadCount() 585
ManagementFactory.getThreadMXBean().getThreadCount() 586
ManagementFactory.getThreadMXBean().getThreadCount() 587
ManagementFactory.getThreadMXBean().getThreadCount() 588
ManagementFactory.getThreadMXBean().getThreadCount() 589
ManagementFactory.getThreadMXBean().getThreadCount() 590
ManagementFactory.getThreadMXBean().getThreadCount() 591
ManagementFactory.getThreadMXBean().getThreadCount() 592
ManagementFactory.getThreadMXBean().getThreadCount() 593
ManagementFactory.getThreadMXBean().getThreadCount() 594
ManagementFactory.getThreadMXBean().getThreadCount() 595
ManagementFactory.getThreadMXBean().getThreadCount() 596
ManagementFactory.getThreadMXBean().getThreadCount() 597
ManagementFactory.getThreadMXBean().getThreadCount() 598

 

 

1 ACCEPTED SOLUTION

Accepted Solutions

olegmir
New Contributor III

Hi,

none of the above suggestion will not work...

we already contacted databricks jdbc team, 

thread leakage was confirmed and was fixed in version 2.6.34

https://mvnrepository.com/artifact/com.databricks/databricks-jdbc/2.6.34
this leakage still exist if you are using Datasource to establish connection.

using DriverManager and version 2.6.34 solves the issue.

View solution in original post

2 REPLIES 2

Kaniz_Fatma
Community Manager
Community Manager

Hi @olegmirBased on the provided information and code, it seems like there is a thread leakage issue when getConnection() it fails in the Databricks JDBC driver. The code provided continuously tries to establish a connection using the DataSource and prints the thread count when an exception occurs. 

To address this issue, you can try the following approaches:

1. Close the connection: Close it after it is used, even in case of exceptions. This can be done by adding a connection.close() statement in the catch block.

2. Use connection pooling: Implement connection pooling to manage and reuse connections efficiently. This can help reduce the number of threads created and improve performance. You can use libraries like HikariCP or Apache Commons DBCP for connection pooling.

3. Increase the maximum number of threads: If the number of lines reaches a limit, you can increase the maximum number of lines the JVM allows. This can be done by setting the -XX:ThreadMax JVM option.

olegmir
New Contributor III

Hi,

none of the above suggestion will not work...

we already contacted databricks jdbc team, 

thread leakage was confirmed and was fixed in version 2.6.34

https://mvnrepository.com/artifact/com.databricks/databricks-jdbc/2.6.34
this leakage still exist if you are using Datasource to establish connection.

using DriverManager and version 2.6.34 solves the issue.

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!