本文介绍了底层的Snowflake驱动程序是否在此处集中了连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此代码:

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;


public Connection fetchSnowflakeConnection(SnowflakeSettings settings) {
    Properties properties = getProperties(settings);
    try {
        String connectStr = null;
        if (StringUtils.isBlank(settings.url)) {
            connectStr = "jdbc:snowflake://us-east-1.blah.com";
        } else {
            connectStr = "jdbc:snowflake://" + settings.url;
        }

        Driver driver = DriverManager.getDriver(connectStr);
        LOG.info("Snowflake driver version: {}.{}", driver.getMajorVersion(),
                driver.getMinorVersion());
        return DriverManager.getConnection(connectStr, properties);
    } catch (Exception e) {
        LOG.error("Problem getting Snowflake connection with these settings: " + settings.toString(),
                e);
    }
    return null;
}

连接是否已池化?我正在使用基本的Java DriverManager,但在Mark的世界中,它正在获取Snowflake驱动程序,该驱动程序汇集了连接.所以

Is the connection pooled? I am using the base java DriverManager but in Mark's world it is getting the Snowflake driver which is pooling the connection. So

DriverManager.getConnection(connectStr, properties);

正在获得连接池.对吧?

is getting a pooled connection. Right?

推荐答案

不,使用 DriverManager.getConnection(…) API调用是一个新建的独立连接对象.

No, what you get with a DriverManager.getConnection(…) API call is a newly built, independent connection object.

连接池是一种缓存管理功能,它此API 在下面调用的Snowflake JDBC驱动程序实现不执行或执行.

A connection pool is a cache management function, which this API and the Snowflake JDBC driver implementation called underneath does not carry or perform.

java.sql软件包下的内置Java类不提供连接池功能,因此您需要使用位于驱动程序之上的第三方库,或滚动您自己的缓存管理.

The inbuilt Java classes under the java.sql package offer no connection pooling features, and you'll need to use a third-party library on top of the drivers, or roll your own cache management.

M o st 驱动程序 实现保持简单,以允许用户在更高的级别上使用选择的连接池模式进行操作,并且不推入任何隐式连接池g.

Most driver implementations are kept simple to allow users to operate with a connection pooling pattern of choice at a higher level, and do not shove-in any implicit connection pooling.

PS ,尽管 DataSource实现可以带有某种形式的连接池,Snowflake的实现(SnowflakeBasicDataSource,截至2020年6月)是一个恰当命名的基本实现,它生成一个每个呼叫的新连接并且不参与在池中.

P.s. Although DataSource implementations can carry some form of connection pooling, Snowflake's implementation (SnowflakeBasicDataSource, as of June 2020) is an aptly-named basic one which generates a new connection per call and does not participate in pooling.

这篇关于底层的Snowflake驱动程序是否在此处集中了连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 09:03
查看更多