クラス org.objectweb.cjdbc.driver.ConnectionClosingThread

org.objectweb.cjdbc.driver.ConnectionClosingThreadのコラボレーション図

Collaboration graph
[凡例]
すべてのメンバ一覧

説明

The ConnectionClosingThread wakes up every 5 seconds when close() has been called on a connection and it frees the connection if it has not been reused.

作者:
Emmanuel Cecchet
バージョン:
1.0

ConnectionClosingThread.java39 行で定義されています。

Public メソッド

 ConnectionClosingThread (Driver driver)
void run ()

Private メソッド

void closeConnection (Connection c)

Private 変数

Driver driver
ArrayList pendingConnectionClosing

Static Private 変数

final int WAIT_TIME = 5000


コンストラクタとデストラクタ

org.objectweb.cjdbc.driver.ConnectionClosingThread.ConnectionClosingThread Driver  driver  ) 
 

Builds a new ConnectionClosingThread

引数:
driver The driver that created us
ConnectionClosingThread.java52 行で定義されています。

参照先 org.objectweb.cjdbc.driver.Driver.connectionClosingThreadisAlive, と org.objectweb.cjdbc.driver.Driver.pendingConnectionClosing.

00053 { 00054 super("ConnectionClosingThread"); 00055 this.driver = driver; 00056 this.pendingConnectionClosing = driver.pendingConnectionClosing; 00057 driver.connectionClosingThreadisAlive = true; 00058 }


メソッド

void org.objectweb.cjdbc.driver.ConnectionClosingThread.closeConnection Connection  c  )  [private]
 

Closes a connection.

引数:
c the connection to close
ConnectionClosingThread.java142 行で定義されています。

参照先 org.objectweb.cjdbc.driver.Connection.driver, org.objectweb.cjdbc.driver.Connection.socket, org.objectweb.cjdbc.driver.Connection.socketInput, と org.objectweb.cjdbc.driver.Connection.socketOutput.

参照元 org.objectweb.cjdbc.driver.ConnectionClosingThread.run().

00143 { 00144 try 00145 { 00146 // Unlink those objects so that this connection can be garbage collected 00147 c.driver = null; 00148 if (c.socketOutput != null) 00149 { 00150 c.socketOutput.writeInt(Commands.Close); 00151 c.socketOutput.flush(); 00152 if (c.socketInput != null) 00153 { // Wait for the controller to receive the connection and close the 00154 // stream. If we do not wait for the controller ack, the connection is 00155 // closed on the controller before the closing is handled which 00156 // results in an ugly warning message on the controller side. We are 00157 // not in a hurry when closing the connection so let do the things 00158 // nicely! 00159 c.socketInput.readObject(); 00160 c.socketInput.close(); 00161 } 00162 c.socketOutput.close(); 00163 } 00164 00165 if (c.socket != null) 00166 c.socket.close(); 00167 } 00168 catch (Exception ignore) 00169 { 00170 } 00171 }

void org.objectweb.cjdbc.driver.ConnectionClosingThread.run  ) 
 

The connection closing thread wakes up every WAIT_TIME seconds when close() has been called on a connection and it frees the connection if it has not been reused. ConnectionClosingThread.java65 行で定義されています。

参照先 org.objectweb.cjdbc.driver.ConnectionClosingThread.closeConnection(), org.objectweb.cjdbc.driver.Driver.connectionClosingThreadisAlive, org.objectweb.cjdbc.driver.ConnectionClosingThread.driver, org.objectweb.cjdbc.driver.ConnectionClosingThread.pendingConnectionClosing, と org.objectweb.cjdbc.driver.ConnectionClosingThread.WAIT_TIME.

00066 { 00067 try 00068 { 00069 Connection firstConnectionToClose = null; 00070 Connection lastConnectionToClose = null; 00071 int pendingConnectionSize; 00072 ArrayList closingList = new ArrayList(); 00073 boolean killed = false; 00074 00075 while (!killed) 00076 { 00077 synchronized (pendingConnectionClosing) 00078 { 00079 pendingConnectionSize = pendingConnectionClosing.size(); 00080 if (pendingConnectionSize == 0) 00081 break; 00082 00083 try 00084 { 00085 // Look at the connections in the queue before sleeping 00086 firstConnectionToClose = (Connection) pendingConnectionClosing 00087 .get(0); 00088 lastConnectionToClose = (Connection) pendingConnectionClosing 00089 .get(pendingConnectionSize - 1); 00090 00091 // Sleep 00092 pendingConnectionClosing.wait(WAIT_TIME); 00093 } 00094 catch (InterruptedException ignore) 00095 { 00096 } 00097 00098 pendingConnectionSize = pendingConnectionClosing.size(); 00099 // Exit, no more connections 00100 if (pendingConnectionSize == 0) 00101 break; 00102 00103 // Compare the queue now with its state when we got to sleep 00104 if (firstConnectionToClose == pendingConnectionClosing.get(0)) 00105 { // Ok, the connection has not been reused, let's close it 00106 if (lastConnectionToClose == (Connection) pendingConnectionClosing 00107 .get(pendingConnectionSize - 1)) 00108 { // No connection has been reused, remove them all 00109 closingList.addAll(pendingConnectionClosing); 00110 pendingConnectionClosing.clear(); 00111 killed = true; // Let's die, there are no more connections 00112 } 00113 else 00114 // Close only the first connection 00115 closingList.add(pendingConnectionClosing.remove(0)); 00116 } 00117 } 00118 00119 // Effectively close the connections outside the synchronized block 00120 while (!closingList.isEmpty()) 00121 closeConnection((Connection) closingList.remove(0)); 00122 } 00123 } 00124 catch (RuntimeException e) 00125 { 00126 e.printStackTrace(); 00127 } 00128 finally 00129 { 00130 synchronized (pendingConnectionClosing) 00131 { 00132 driver.connectionClosingThreadisAlive = false; 00133 } 00134 } 00135 }


変数

Driver org.objectweb.cjdbc.driver.ConnectionClosingThread.driver [private]
 

ConnectionClosingThread.java44 行で定義されています。

参照元 org.objectweb.cjdbc.driver.ConnectionClosingThread.run().

ArrayList org.objectweb.cjdbc.driver.ConnectionClosingThread.pendingConnectionClosing [private]
 

ConnectionClosingThread.java45 行で定義されています。

参照元 org.objectweb.cjdbc.driver.ConnectionClosingThread.run().

final int org.objectweb.cjdbc.driver.ConnectionClosingThread.WAIT_TIME = 5000 [static, private]
 

ConnectionClosingThread.java42 行で定義されています。

参照元 org.objectweb.cjdbc.driver.ConnectionClosingThread.run().


このクラスの説明は次のファイルから生成されました:
CJDBCversion1.0.1に対してWed Aug 18 09:20:31 2004に生成されました。 doxygen 1.3.8