Skip to content

Consider using "TimeUnit.<unit>.sleep(x)" for code examples #1518

Description

@polleyg

In most code examples given (both in GitHub & official docs) where a sleep is needed, then Thread.sleep(x) is used. For example:

For better readability/clarity, then it may be prudent to consider using the TimeUnit class instead. Yes, it's all the same as it calls Thread.sleep(x) under the hood, but consider the following as an example:

Thread.sleep(180000) vs. TimeUnit.MINUTES.sleep(3)

More info: http://stackoverflow.com/questions/9587673/thread-sleep-vs-timeunit-seconds-sleep

Activity

  1. lesv commented on Feb 24, 2017

    @lesv
    Contributor

    Better not to include sleep in the samples, unless we expect users to use it as well. Instead put them in the tests for those samples.

    However, if you really most use sleep, then this probably should be preferred.

  2. added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Jun 12, 2017
  3. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    on Nov 9, 2017
  4. yihanzhen commented on Jan 10, 2018

    @yihanzhen
    Contributor

    The feature request is added to the backlog. The issue will be closed but is linked in the backlog and can continue to be used for comment and discussion.

  5. added a commit that references this issue on Mar 23, 2026
  6. added a commit that references this issue on Mar 30, 2026
  7. added a commit that references this issue on Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: corepriority: p2Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions