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 1040221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:11:48+00:00 2026-05-16T15:11:48+00:00

I am finding often the need to very often wait until the next second

  • 0

I am finding often the need to very often wait until the next second to do the next operation in a series. This slows down unit tests quite considerably. So here’s my question:

Instead of doing Thread.sleep(1000) is there a quicker more efficient way to sleep until the second changes to the next second?

Say the time is 1:00:89

I sleep one second to 1:01:89

I would rather continuing executing when the time hits 1:01
or as close as possible.

Is this reasonably possible? ^_^

  • 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-05-16T15:11:49+00:00Added an answer on May 16, 2026 at 3:11 pm

    Well, you could do something like:

    long millisWithinSecond = System.currentTimeMillis() % 1000;
    Thread.sleep(1000 - millisWithinSecond);
    

    It won’t be exact, mind you – you may need to iterate, which is a bit messy.

    However, it would be better not to have to sleep at all. Could you inject a “sleeping service” which would allow you to fake the sleeps out in tests? (I’ve rarely needed to do that, but I’ve often injected a fake clock to report different times.) What’s the purpose of sleeping in the production code at all?

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

Sidebar

Related Questions

I'm finding this kind of overriding after a new in java code very often
I'm often finding the need to validate a set of conditions, and instead of
I am finding myself doing the following a bit too often: attr = getattr(obj,
I am having trouble finding an answer to this. Consider the clipping code below:
I'm having trouble finding a way to do this in a way that doesn't
Finding myself in the situation where I have a method with this signature void
Finding lots of mixed answers on this from Google - but mostly 2-3 years
I often do this kind of mistake, instead of: Toast.makeText(this, getString(R.string.string_id), Toast.LENGTH_SHORT).show(); i do
I'm having problems with Ruby scripts finding the right gems. It seems this is
As I implement the MVVM pattern with WPF, I'm finding that ReSharper is often

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.