0

Web アプリケーションを WebLogic にデプロイしました。この Web アプリケーションには、DB への接続を試行するサーブレットがあり、失敗した場合は、構成された一定時間待機/一時停止/スリープし、DB への接続を再試行します。(実際には、指数関数的に N 回待機して試行し、すべての試行が失敗した場合、FAILURE 応答を返します)。

2回の試行の間に待機/一時停止するために、使用しました

Thread.sleep();

しかし、8 つの weblogic 管理対象サーバーが実行されている運用環境では、Thread.sleep() が信頼できないことがわかりました。構成された時間より長くスリープします。

これに対する回避策はありますか?

アップデート:

これが私のコードです。管理対象サーバーの活性化からこれを呼び出していることに注意してください。

public final void checkDBHealth() throws Throwable {

       for (int attempt=0; attempt<BACK_OFF_MAX_ATTEMPTS; attempt++) {
              try {
                     pauseExponentially(attempt);
                     connect();
                     execute();
                     close();
                     return;
              } catch (final Throwable th) {                 
                     if (ExceptionType.NON_RETRIABLE == ExceptionAnalyzer.translate(th) || (BACK_OFF_MAX_ATTEMPTS-1) == attempt) {
                            throw th;
                           // If exception is thrown I send the failure message
                     }
              }
       }

    }




  private void pauseExponentially(final int attempt) {
       if (attempt == 0) {
            return;
       }

        final long delay = (long) (((int)Math.pow(BACK_OFF_BASE, attempt)) * THOUSAND);
        try {
            Thread.sleep(delay);
        } catch (IE e) {…}

    }
4

1 に答える 1