J2ee アプリケーションで StaleConnectionException が発生しました。私は調べて(そして検索して)、解決策を見つけました。
ここにあります。
public static Connection getConnection() {
Connection conn = null;
try {
if (ds == null) ds = (DataSource) new Utility.makeLookup();
conn = ds.getConnection();
conn.setAutoCommit(false);
// Check quality of return connection
Statement stmt = conn.createStatement();
stmt.executeQuery("Select 1 from dual");
stmt.close();
} catch (Throwable t) {
try {
// Recovery
ds = (DataSource) new Utility.makeLookup();
conn = ds.getConnection();
conn.setAutoCommit(false);
return conn;
} catch (Throwable t2) { /* RIP */ }
}
return conn;
}
StaleConnectionException を管理する必要がある場合、最初のメソッド呼び出しで 6 秒の最初のラグがあるため、このソリューションは好きではありません。
新しいブラウザ セッションの開始時に接続をテストしますが、これも気に入りません。
私が実装できるより良いものはありますか?
前もって感謝します。
クワック