hi,
I wrote a DBConnectionPool and DBConnectionPoolServlet. All db
related servlets will get a connection from DBConnectionPoolServlet when they
need to run a query. Now I would like to know that when does a servlet
upload itself? Will it be automatically uploaded (may be because of memory/...)
or it only be uploaded when the server is shutting down? Because when
DBConnectionPoolServlet is uploaded(destroy), all the connections from that
servlet will be closed. Then the servlets, which are holding a connection from
that pool, will have a trouble, because the connection that they have is
closed.
If the servlet will automatically upload itself, then is it a
good idea to do something like this:
DBConnectionPool.java
...
// lockedConnections and
unlockedConnections are vectors that hold locked and unlocked
connections.
public void destroy() throws
ConnectionsStillActiveException, SQLException{
if(lockedConnections.size()!=0)
throw
new ConnectionsStillActive();
for(int
i=0;i<unlockedConnections.size();i++)
((Connection)unlockedConnections.elementAt(i)).close()
}
....
DBConnectionPoolServlet.java
....
public void destroy(){
boolean
okToDestroy=false;
while(!okToDestroy){
//loop until all the connections returned
okToDestroy=true;
try{
try{
pool.destroy();
}catch(ConnectionsStillActiveException csaex){
orToDestroy=false;
}
catch(SQLException sqlex){
log("sqlexception at DBConnectionPoolServlet.destroy");
}
}
super.destroy()
}
....
re: it's will raise another problem when there
is a connection never return to the pool! What should I
do????
