JDBC -- Connection Pool
时间:2021-07-01 10:21:17
帮助过:3人阅读
com.pp.pool;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import com.pp.util.JdbcUtil;
/*
* Simulate the completion of connetion pool
*/
public class SimpleConnectionPool {
private static List<Connection> pool =
new ArrayList<Connection>
();
static {
for (
int i = 0; i < 10; i++
) {
Connection conn =
JdbcUtil.getConnection();
pool.add(conn);
}
}
// get the connection object from cache pool
public synchronized static Connection getConnection() {
if (pool.size() > 0
) {
Connection conn = pool.remove(0
);
return conn;
} else {
throw new RuntimeException("Server is busy!"
);
}
}
// return the connection
public static void releas(Connection conn) {
pool.add(conn);
}
}
JDBC -- Connection Pool
标签:syn exce into for stat jdb nec size and