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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:11:54+00:00 2026-06-15T14:11:54+00:00

I want that my program wait 10s in my while true, but it doesn’t

  • 0

I want that my program wait 10s in my while true, but it doesn’t work
I tried to use Thread.sleep(10000); but it isn’t 10s

while (true) {
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 5; j++) {
            if (matrixVacancy[i][j] == 1) {
                completeParking(i, j, R.color.vaga_ocupada);
            } else {
                completeParking(i, j, R.color.cor_chao);
            }
        }
    }
    try {
        Thread.sleep(10000);
    } catch (InterruptedException ex) {
    }

    int a, b, c, d, e, f, g, h, i;

    a = (int) (Math.random() * 2); // indice i
    b = (int) (Math.random() * 5); // indice j
    c = (int) (Math.random() * 2); // tem ou nao carro

    d = (int) (Math.random() * 2); // indice i
    e = (int) (Math.random() * 5); // indice j
    f = (int) (Math.random() * 2); // tem ou nao carro

    g = (int) (Math.random() * 2); // indice i
    h = (int) (Math.random() * 5); // indice j
    i = (int) (Math.random() * 2); // tem ou nao carro

    matrixVacancy[a][b] = c;
    matrixVacancy[d][e] = f;
    matrixVacancy[g][h] = i;
}

How can I do it? For my while wait 10s?

  • 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-15T14:11:55+00:00Added an answer on June 15, 2026 at 2:11 pm

    Depends what thread your trying to sleep. You can also put your method in a seperate thread and do your methods there. This way your app will not hang/sleep

    private class TimeoutOperation extends AsyncTask<String, Void, Void>{
    
        @Override
        protected Void doInBackground(String... params) {
    
            try {
                Log.i(TAG, "Going to sleep");
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return null;
        }
    
        @Override
        protected void onPostExecute(Void result) {
            Log.i(TAG, "This is executed after 10 seconds and runs on the main thread");
            //Update your layout here
            super.onPostExecute(result);
        }
    }
    

    To run this operation use

    new TimeoutOperation().execute("");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display a progress bar while doing some work, but that would
I'll write a script that runs a program and wait for it finished. But
I want to spawn a Java thread from my main java program and that
I just want that my program or method should run at specific date and
With win32api, I want that the following program creates two process and creates a
I want a program that would help me create virtual devices on a virtual
I want a program that runs continually and monitors the time constantly. When it's
I have a program that I want to distribute, without giving the source code
I have a program that I want to either hide or show certain UIbuttons
I've got a small Perl program that I want to run on the command

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.