Java Sleep sleepBeforeRetry(int attemptNumber)

Here you can find the source of sleepBeforeRetry(int attemptNumber)

Description

Used in case we need to re-submit request to AWS when it throws 'AWS Error Code: ServiceUnavailable, AWS Error Message: Service AmazonSimpleDB is currently unavailable.

License

Apache License

Parameter

Parameter Description
attemptNumber a parameter

Declaration

public static void sleepBeforeRetry(int attemptNumber) 

Method Source Code

//package com.java2s;
/* Copyright (C) 2011 SpringSource
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License./*  w  ww. jav  a  2 s .  c o m*/
 */

public class Main {
    /**
     * Used in case we need to re-submit request to AWS when it throws 'AWS Error Code: ServiceUnavailable, AWS Error Message: Service AmazonSimpleDB is currently unavailable. Please try again '
     * @param attemptNumber
     */
    public static void sleepBeforeRetry(int attemptNumber) {
        long sleepMS;
        if (attemptNumber < 5) {
            sleepMS = 100;
        } else if (attemptNumber < 10) {
            sleepMS = 1000;
        } else if (attemptNumber < 15) {
            sleepMS = 5000;
        } else if (attemptNumber < 20) {
            sleepMS = 30000;
        } else {
            sleepMS = 60000;
        }
        try {
            Thread.sleep(sleepMS);
        } catch (InterruptedException e) {
        }
    }
}

Related

  1. sleepABitMore()
  2. sleepAfterListItems()
  3. sleepAndIgnoreInterrupts(int millis)
  4. sleepAtLeast(long milliseconds)
  5. sleepAtLeast(long milliseconds)
  6. sleepButInterruptable(long msecs)
  7. sleepCurrentThread()
  8. sleepDeep(long millis)
  9. sleepExp(int countFailures)