Commit e04d3559 authored by 赵建伟's avatar 赵建伟

update codes

parent 9d347b7e
......@@ -29,7 +29,6 @@ public class JdbcConnectPool {
for (int i = 0; i < Integer.valueOf(prop.getProperty("initSize")); i++) {
Connection connection = createConnect();
connList.add(connection);
//currentsize++;
}
}
......@@ -40,21 +39,18 @@ public class JdbcConnectPool {
*/
public static Connection getConnect() {
Connection connection = null;
int connSize = connList.size();
if (connSize > 0) {
if (connList.size() > 0) {
connection = connList.getFirst();
connList.removeFirst();
//currentsize--;
} else{
while(connSize < Integer.valueOf(prop.getProperty("maxSize"))){
while(connList.size() < Integer.valueOf(prop.getProperty("maxSize"))){
connList.addLast(createConnect());
//currentsize++;
}
connection = getConnect();
}
requestCount ++;
logger.info("requestCount : {}",requestCount);
logger.info("connList size : {}",connSize);
logger.info("connList size : {}",connList.size());
return connection;
}
......@@ -66,7 +62,9 @@ public class JdbcConnectPool {
private static Connection createConnect() {
Connection conn = null;
try {
conn = DriverManager.getConnection(prop.getProperty("url"), prop.getProperty("username"),
conn = DriverManager.getConnection(
prop.getProperty("url"),
prop.getProperty("username"),
prop.getProperty("password"));
} catch (SQLException e) {
e.printStackTrace();
......
package com.gmei.data.dqmp.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;
public class JdbcUtils {
private static final Logger logger = LoggerFactory.getLogger(JdbcUtils.class);
private static Properties prop;
static {
prop = getProperties("jdbc.properties");
try {
Class.forName(prop.getProperty("driverClassName"));
} catch (ClassNotFoundException e) {
e.printStackTrace();
logger.error(e.getMessage());
}
}
public static Connection getConnection() throws Exception {
Connection connection = DriverManager.getConnection(
prop.getProperty("url"),
prop.getProperty("username"),
prop.getProperty("password"));
return connection;
}
/**
* 获取属性文件对象
*
* @param path
* @return
*/
private static Properties getProperties(String path) {
Properties properties = new Properties();
try {
InputStream inputStream = JdbcUtils.class.getClassLoader().getResourceAsStream(path);
properties.load(inputStream);
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage());
}
return properties;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment