public class BookDBAO {
Connection conn;
private ArrayList bookContainer;
private boolean conFree=true;
public BookDBAO() throws Exception {
try{
Class.forName(Constant.dbConnStr[0]);
conn=DriverManager.getConnection(Constant.dbConnStr[3],Constant.dbConnStr[1],Constant.dbConnStr[2]);
}catch(Exception e){
throw new Exception("Countn't get Connection Object!"+e.getMessage());
}
}
public void remove(){
try {
conn.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
public synchronized Connection getConection(){
while (!conFree){
try {
wait();
} catch (InterruptedException e) {
}
}
conFree=false;
notify();
return conn;
}
public synchronized void releaseConnection(){
while(conFree){
try {
wait();
} catch (InterruptedException e) {
}
}
conFree=true;
notify();
}
说说getConnection,releaseConnection 这两个方法看不懂,不能理解。请大家说详细点。谢谢!
Connection conn;
private ArrayList bookContainer;
private boolean conFree=true;
public BookDBAO() throws Exception {
try{
Class.forName(Constant.dbConnStr[0]);
conn=DriverManager.getConnection(Constant.dbConnStr[3],Constant.dbConnStr[1],Constant.dbConnStr[2]);
}catch(Exception e){
throw new Exception("Countn't get Connection Object!"+e.getMessage());
}
}
public void remove(){
try {
conn.close();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
public synchronized Connection getConection(){
while (!conFree){
try {
wait();
} catch (InterruptedException e) {
}
}
conFree=false;
notify();
return conn;
}
public synchronized void releaseConnection(){
while(conFree){
try {
wait();
} catch (InterruptedException e) {
}
}
conFree=true;
notify();
}
说说getConnection,releaseConnection 这两个方法看不懂,不能理解。请大家说详细点。谢谢!
在你getConnection完成以后releaseConnection 才能对这个connection做操作