Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.controller.connection.VariablePoolConnectionManager.RemoveIdleConnectionsThread Class Reference

List of all members.

Public Member Functions

void run ()

Protected Member Functions

 RemoveIdleConnectionsThread (String pBackendName)

Detailed Description

Allows to remove idle free connections after the idleTimeout timeout.

Author:
Mathieu Peltier

Definition at line 504 of file VariablePoolConnectionManager.java.


Member Function Documentation

void org.objectweb.cjdbc.controller.connection.VariablePoolConnectionManager.RemoveIdleConnectionsThread.run  ) 
 

See also:
java.lang.Runnable#run()

Definition at line 516 of file VariablePoolConnectionManager.java.

References org.objectweb.cjdbc.common.log.Trace.debug(), and org.objectweb.cjdbc.common.log.Trace.error().

00517     {
00518       long idleTime, releaseTime;
00519       synchronized (this)
00520       {
00521         try
00522         {
00523           while (!isKilled)
00524           {
00525             // the thread is not launched if idleTimeout equals to 0 (the
00526             // connections are never released in this case)
00527             if (freeConnections.isEmpty()
00528                 || (freeConnections.size() == minPoolSize))
00529             {
00530               wait();
00531             }
00532 
00533             Connection c = null;
00534             synchronized (freeConnections)
00535             {
00536               if (releaseTimes.isEmpty())
00537                 continue; // Sanity check
00538 
00539               releaseTime = ((Long) releaseTimes.get(0)).longValue();
00540               idleTime = System.currentTimeMillis() - releaseTime;
00541 
00542               if (idleTime >= idleTimeout)
00543                 c = (Connection) freeConnections.remove(0);
00544             }
00545 
00546             if (c == null)
00547             { // Nothing to free, wait for next deadline
00548               wait(idleTimeout - idleTime);
00549             }
00550             else
00551             { // Free the connection out of the synchronized block
00552               try
00553               {
00554                 c.close();
00555               }
00556               catch (SQLException e)
00557               {
00558                 String msg = "An error occured while closing idle connection after the timeout: "
00559                     + e;
00560                 logger.error(msg);
00561               }
00562               finally
00563               {
00564                 releaseTimes.remove(0);
00565                 poolSize--;
00566               }
00567               logger.debug("Released idle connection (idle timeout reached)");
00568               continue;
00569 
00570             }
00571           }
00572         }
00573         catch (InterruptedException e)
00574         {
00575           logger
00576               .error("Wait on removeIdleConnectionsThread interrupted in VariablePoolConnectionManager: "
00577                   + e);
00578         }
00579       }
00580     }


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:03:42 2005 for C-JDBC by  doxygen 1.3.9.1