[TD-4939]<test>: add a Proxool Connection Pool Demo (#6657)
* [TD-4939]<test>: add a Proxool Connection Pool Demo * change
This commit is contained in:
parent
c4f96ffc98
commit
7f2e888bbc
|
@ -9,12 +9,12 @@
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!-- taos -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.18</version>
|
<version>2.0.18</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- druid -->
|
<!-- druid -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
|
@ -50,6 +50,12 @@
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>1.2.17</version>
|
<version>1.2.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- proxool -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.cloudhopper.proxool</groupId>
|
||||||
|
<artifactId>proxool</artifactId>
|
||||||
|
<version>0.9.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -57,25 +63,46 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.3.0</version>
|
||||||
<configuration>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>com.taosdata.example.ConnectionPoolDemo</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
</configuration>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>make-assembly</id>
|
<id>ConnectionPoolDemo</id>
|
||||||
|
<configuration>
|
||||||
|
<finalName>ConnectionPoolDemo</finalName>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>com.taosdata.example.ConnectionPoolDemo</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>single</goal>
|
<goal>single</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
|
|
||||||
|
<execution>
|
||||||
|
<id>ProxoolDemo</id>
|
||||||
|
<configuration>
|
||||||
|
<finalName>ProxoolDemo</finalName>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>com.taosdata.example.ProxoolDemo</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package com.taosdata.example;
|
||||||
|
|
||||||
|
import org.logicalcobwebs.proxool.ProxoolException;
|
||||||
|
import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class ProxoolDemo {
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
String xml = parseConfigurationXml(args);
|
||||||
|
if (xml == null) {
|
||||||
|
printHelp();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
JAXPConfigurator.configure(xml, false);
|
||||||
|
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
|
||||||
|
Connection connection = DriverManager.getConnection("proxool.ds");
|
||||||
|
|
||||||
|
Statement stmt = connection.createStatement();
|
||||||
|
|
||||||
|
ResultSet rs = stmt.executeQuery("show databases");
|
||||||
|
ResultSetMetaData metaData = rs.getMetaData();
|
||||||
|
while (rs.next()) {
|
||||||
|
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
||||||
|
System.out.print(metaData.getColumnLabel(i) + ": " + rs.getString(i));
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt.close();
|
||||||
|
|
||||||
|
} catch (ClassNotFoundException | SQLException | ProxoolException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String parseConfigurationXml(String[] args) {
|
||||||
|
String host = null;
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
if ("--xml".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
||||||
|
host = args[++i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void printHelp() {
|
||||||
|
System.out.println("Usage: java -jar ProxoolDemo.jar --xml [xml]");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<something-else-entirely>
|
||||||
|
<proxool>
|
||||||
|
<alias>ds</alias>
|
||||||
|
<!--数据源的别名-->
|
||||||
|
<driver-url>jdbc:TAOS-RS://127.0.0.1:6041/log</driver-url>
|
||||||
|
<!--url连接串-->
|
||||||
|
<driver-class>com.taosdata.jdbc.rs.RestfulDriver</driver-class>
|
||||||
|
<!--驱动类-->
|
||||||
|
<driver-properties>
|
||||||
|
<property name="user" value="root"/>
|
||||||
|
<property name="password" value="taosdata"/>
|
||||||
|
</driver-properties>
|
||||||
|
<!--最大连接数(默认5个),超过了这个连接数,再有请求时,就排在队列中等候,最大的等待请求数由maximum-new-connections决定 -->
|
||||||
|
<maximum-connection-count>100</maximum-connection-count>
|
||||||
|
<!-- 定义连接池中的最大连接数 -->
|
||||||
|
<maximum-active-time>100</maximum-active-time>
|
||||||
|
<!--最少保持的空闲连接数(默认2个)-->
|
||||||
|
<prototype-count>1</prototype-count>
|
||||||
|
<!--最小连接数(默认2个)-->
|
||||||
|
<minimum-connection-count>5</minimum-connection-count>
|
||||||
|
<!--proxool自动侦察各个连接状态的时间间隔(毫秒),侦察到空闲的连接就马上回收,超时的销毁 默认30秒-->
|
||||||
|
<house-keeping-sleep-time>30000</house-keeping-sleep-time>
|
||||||
|
<!--用于保持连接的测试语句 -->
|
||||||
|
<house-keeping-test-sql>select server_status()</house-keeping-test-sql>
|
||||||
|
</proxool>
|
||||||
|
</something-else-entirely>
|
Loading…
Reference in New Issue