Hi,
Suppose here that you want to be sure that some objects
(DatabasePool is one of them) will never be destroyed.
(due to servlet engine's decisions on when is necessary to unload
- ??upload?? - a servlet)
Probably the safest way is to run a non-daemon thread that keeps referrence
to these objects, so they never get collected.
In the following example I did not understood why do you don't use directly
the DbConnectionPool when you need to get/free a connection, but use a
DbConnectionPoolServlet instead.
----------------------------------------
Some thoughts for the question about the never-returned connections:
I've seen some pools (in GSP sources, not sure) that the pool writer
implemented a connection wrapper, wich is instantiated with a "real"
connection obtained from database drivers.
All its methods (implementing Connection interface) take these steps:
{
check a local boolean flag to see if this connection is expired.
if yes, throw SQLException;
touch an internal timestamp with current time;
in the end call the same method of the contained inner Connection,
with the same arguments;
}
>From time-to-time the DbPool checks each non-free connection for timeouts.
(to see if the connection is unused for a time)
Sets the boolean flag for those expired, closing their contained
"real" connection, and removing all DbPool-maintained referrences to
these expired connections.
Application programs will fail to use the "expired" connection,
and will have to handle this kind of error like any other SQL exception
(perhaps by requesting a new "valid" connection from your database pool).
Cezar.
On Sat, 17 Apr 1999, Alvin, lau wrote:
> hi,=20
>
> 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()!=3D0)
> throw new ConnectionsStillActive();
> for(int i=3D0;i<unlockedConnections.size();i++)
> ((Connection)unlockedConnections.elementAt(i)).close()
> }
> .... =20
>
> DBConnectionPoolServlet.java
> ....
> public void destroy(){
> boolean okToDestroy=3Dfalse;
> while(!okToDestroy){ //loop until all the =
> connections returned
> okToDestroy=3Dtrue;
> try{
> try{
> pool.destroy();
> }catch(ConnectionsStillActiveException csaex){
> orToDestroy=3Dfalse;
> }
> 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????
>
Cezar Totth email: [EMAIL PROTECTED]
Fax: (401) 220 33 95
Genesys Software Romania Phone: (401) 638 49 44
Stefan Furtuna 169, sect.6
cod 77171, Bucharest
Romania
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html