public class ConnectionManager {
private static int allConnection;//所有连接数
private static int connectionsNum;//剩余连接数
private static Connection[] connections = new Connection[5];
static{
for(int i = 0 ; i < connections.length ; i++){
connections[i] = new Connection();
allConnection = connectionsNum = 5 ;
}
}
static Connection getConnection(){
if(allConnection - connectionsNum != 0){
connectionsNum--;
return connections[allConnection - connectionsNum];
} else {
return null;
}
}
static void close(){
connectionsNum++;
connections[allConnection - connectionsNum] = new Connection();
}}自己想象着写了一个,不知道真正的连接池是不是这样工作的。
解决方案 »
- 关于电子口岸xml报文设计
- 并发测试EJB的问题,请高手帮忙,发我MAIL( [email protected] )或回复,万分感谢
- hibernate链接oracle问题求助
- 如何保证在页面跳转时仍然保持在同一个Request过程中
- 日期一更新,就出现下面错误,请高手指点。
- 一个错误信息,高手帮我看看,谢谢(struts in action的例子)
- ejb访问sqlserver数据库出错。
- 100分求jboss 4.0 下的一个"hello world" jsp\servlet 例子
- Spring ApplicationContext Bean的生命周期
- 使用jacob操作word文档时出现弹窗,导致程序卡死
- 今年毕业找JAVA工作遇到困难, 大家都来讨论下!迷茫不解中!!!
- 数组的[[ 和]
不过 getConnection()需要一个同步