Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8718433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:32:49+00:00 2026-06-13T06:32:49+00:00

Background: I’ve been habitually converting Thread.sleep() calls to TimeUnit.XXX.sleep() calls, whenever I need to

  • 0

Background: I’ve been habitually converting Thread.sleep() calls to TimeUnit.XXX.sleep() calls, whenever I need to otherwise touch code containing that.

Questions: First of all, is this ok, or is there some subtle problem with TimeUnit’s sleep? Then, as far as I’ve figured out, this is best way to wait before a network (or similar) operation retry like

for(int retriesLeft = 3; ;--retriesleft) {
    try {
        doOperation(...);
        break;
    } catch (IOException ex) {
        if (retryCountDown <= 0) throw ex;
        else TimeUnit.SECONDS.sleep(10);
    }
}

Is TimeUnit.XXXX.sleep(10) the right way to sleep above, or is there a better way? Also, feel free to comment if there’s a better Java pattern to handle the whole network operation retry logic…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:32:50+00:00Added an answer on June 13, 2026 at 6:32 am

    Thread.sleep() only accepts time in milliseconds.Therefore a helper class was introduced TimeUnit which would specify the units like SEC, HOURs which is much more convenient thn inputting milliseconds. It helps in increasing the readability of the code also.

    check the javadoc: http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/TimeUnit.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I've been running a code (posted at the bottom) to measure performance of
Background: What I need to accomplish is to remove any records in a collection
Background : I'm trying to convert some JavaScript code which uses the the Crossfilter
Background I've been searching for a while for a layout which has 960px width
Background I've recently started to develop some code using the NDK, and I've thought
BACKGROUND I am writing a screen capture application My code is based derived from
Background Below is a typical piece of Perl code ( sample.pl for the sake
Background I've recently been a part of a project where twisted was used. We
Background: We're building an application that allows our customers to supply data in a
Background: I'm using the (fantastic) Vim plugin python-mode , which includes the pep8 linter.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.