AWSNeptune连接池设置
创始人
2024-09-26 16:01:39
0

在使用AWS Neptune数据库时,我们可以使用以下代码示例来设置连接池:

import com.amazonaws.regions.Regions;
import com.amazonaws.services.neptune.AmazonNeptune;
import com.amazonaws.services.neptune.AmazonNeptuneClientBuilder;
import com.amazonaws.services.neptune.model.DBInstanceNotFoundException;

import java.util.Properties;

import org.apache.commons.dbcp2.BasicDataSource;

public class NeptuneConnectionPool {

    private BasicDataSource dataSource;

    public NeptuneConnectionPool(String endpoint, String port, String dbName, String username, String password, Regions region) throws Exception {
        dataSource = new BasicDataSource();

        dataSource.setUsername(username);
        dataSource.setPassword(password);
        dataSource.setUrl("jdbc:aws://" + endpoint + ":" + port + "/" + dbName + "?region=" + region.getName());
        dataSource.setDriverClassName("com.amazon.neptune.driver.GremlinDriver");

        // maximum number of active connections to allocate
        dataSource.setMaxTotal(20);

        // maximum number of connections to allow in the idle state
        dataSource.setMaxIdle(0);

        // minimum number of connections to allow in the idle state
        dataSource.setMinIdle(0);

        // maximum waiting time for an idle connection to become available
        dataSource.setMaxWaitMillis(10000);

        // validate connection before borrowing it from pool
        dataSource.setValidationQuery("SELECT 1");

        // check idle connection periodically
        dataSource.setTimeBetweenEvictionRunsMillis(60000);

        // validate idle connections during idle connection check
        dataSource.setTestWhileIdle(true);
    }

    public AmazonNeptune getConnection() throws DBInstanceNotFoundException {
        AmazonNeptune client = AmazonNeptuneClientBuilder.standard().withCredentials(new DefaultAWSCredentialsProviderChain()).build();
        client.describeDBInstances();
        client.shutdown();
        return client;
    }

    public BasicDataSource getDataSource() {
        return dataSource;
    }

    public void close() {
        try {
            dataSource.close();
        } catch (Exception e) {
        }
    }

}

其中,我们可以设置以下参数:

  • dataSource.setMaxTotal(20):连接池最大连接数
  • dataSource.setMaxIdle(0):最大空闲连接数
  • dataSource.setMinIdle(0):最小空闲连接数
  • `dataSource.setMaxWaitMillis(100

相关内容

热门资讯

科普分享“Wepoker透视免... 您好:Wepoker透视免费版的软件,软件加客服确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用...
每日必备“WePoKer辅助挂... 无需打开直接搜索;操作使用教程:每日必备“WePoKer辅助挂怎么下载”开挂辅助脚本(透视)科技教程...
科普分享“wePoKer有透视... 科普分享“wePoKer有透视软件吗”开挂辅助挂(透视)安装教程是一款可以让一直输的玩家,快速成为一...
最新技巧“wepoker是不是... 最新技巧“wepoker是不是有透视软件”开挂辅助平台(透视)曝光教程是一款可以让一直输的玩家,快速...
重要通知“有wepoker透视... 无需打开直接搜索加微信客服(136704302)咨询了解有wepoker透视吗辅助器目前(微信:13...
科普常识“wepoker透视辅... 科普常识“wepoker透视辅助挂的功能介绍”开挂辅助安装(透视)靠谱教程是一款可以让一直输的玩家,...
玩家必用“wepoker辅助软... 玩家必用“wepoker辅助软件安全吗”开挂辅助插件(透视)实用技巧是一款可以让一直输的玩家,快速成...
我来教教你“微乐扑克记牌器怎么... 您好:微乐扑克记牌器怎么用这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户...
玩家必知教程“wepoker冤... 您好:wepoker冤家牌规律这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...
开挂辅助软件"wep... 开挂辅助软件"wepoker透视脚本免费下载pc"开挂(透视)辅助脚本(有挂分析)【无需打开直接搜索...