//get connection and set to delay time
long startTime = new java.util.Date().getTime();
Connection con = null;
while (con == null) {
con = newConnection();
if (con != null) {
//log("Create New Connection!");
break;
}
try {
log("连接超时,重新连接,等待" + timeout + "ms");
wait(timeout);
}
catch (InterruptedException e) {
log(e, "连接超时!");
}
if ( (new java.util.Date().getTime() - startTime) >= timeout) {
log("Connection timeout!");
break;
}
}
return con;
}
private
Connection newConnection() {
Connection con = null;
try {
con = ds.getConnection();
if (con == null) {
throw new Exception("Create Connection Failed!");
}
}
catch (Exception e) {
log("Create Connection Failed!");
System.out.println(e.getMessage());
}
return con;
}
/************************************
* release the connection
* @param conn Connection
* @param stmt Statement
* @param pstmt PreparedStatement
************************************/
public synchronized
void freeConnection(Connection conn,
Statement stmt,
PreparedStatement pstmt) {
try {
//close Statement
if (stmt != null) {
stmt.close();
| 对此文章发表了评论 |
