Revision 739
Added by bojilova over 23 years ago
src/edu/ucsb/nceas/metacat/DBQuery.java | ||
---|---|---|
226 | 226 |
} |
227 | 227 |
|
228 | 228 |
try { |
229 |
if(conn == null) |
|
229 |
if(conn == null || conn.isClosed())
|
|
230 | 230 |
{ |
231 | 231 |
dbconn = util.openDBConnection(); |
232 | 232 |
} |
src/edu/ucsb/nceas/metacat/MetaCatUtil.java | ||
---|---|---|
136 | 136 |
conn = (Connection)connections.nextElement(); |
137 | 137 |
Boolean b = (Boolean)connectionPool.get(conn); |
138 | 138 |
|
139 |
if (conn == null) { |
|
139 |
if (conn == null || conn.isClosed()) {
|
|
140 | 140 |
// closed connection; replace it |
141 | 141 |
conn = openDBConnection(); |
142 | 142 |
// update the pool to show this one taken |
... | ... | |
189 | 189 |
Connection conn; |
190 | 190 |
Enumeration connections = connectionPool.keys(); |
191 | 191 |
|
192 |
if (returned != null) { |
|
193 |
while (connections.hasMoreElements()) { |
|
194 |
conn = (Connection)connections.nextElement(); |
|
195 |
if ( conn == returned ) { |
|
192 |
try { |
|
193 |
if ( (returned != null) && !(returned.isClosed()) ) { |
|
194 |
while (connections.hasMoreElements()) { |
|
195 |
conn = (Connection)connections.nextElement(); |
|
196 |
if ( conn == returned ) { |
|
196 | 197 |
connectionPool.put( conn, Boolean.FALSE ); |
197 | 198 |
break; |
199 |
} |
|
198 | 200 |
} |
199 |
}
|
|
200 |
} |
|
201 |
} |
|
202 |
} catch (SQLException e) {}
|
|
201 | 203 |
} |
202 | 204 |
|
203 | 205 |
/* Return the size of the pool */ |
... | ... | |
213 | 215 |
|
214 | 216 |
while (connections.hasMoreElements()) { |
215 | 217 |
conn = (Connection)connections.nextElement(); |
216 |
if ( conn != null ) {
|
|
217 |
try {
|
|
218 |
conn.close();
|
|
219 |
} catch (SQLException e) {}
|
|
220 |
} |
|
218 |
try {
|
|
219 |
if ( (conn != null) && !(conn.isClosed()) ) {
|
|
220 |
conn.close(); |
|
221 |
} |
|
222 |
} catch (SQLException e) {}
|
|
221 | 223 |
} |
222 | 224 |
} |
223 | 225 |
|
Also available in: Unified diff
as John were testing Metacat on postgres,
he discovered that Connection needs more precise check
whether it is open because of db timing outs.
So used to be:
if ( conn null ) { get new connection from db; }
Now changed to:
if ( conn null || conn.isClosed() ) { get new connection from db; }
Hope this will solve the problems with errors as:
Connection reset by peer, etc.