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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:05:26+00:00 2026-05-26T22:05:26+00:00

I really don’t like posting multiple questions in a go, sorry if this is

  • 0

I really don’t like posting multiple questions in a go, sorry if this is annoying.

I finally managed to fix my problem. Except I’m not sure if it is reliable or even wise.

   public void run() {
            // TODO Auto-generated method stub


            float time = 0.01f;
            try {
                while(time < timer)
                {
                       time+=0.1f;
                                       Thread.sleep(100);
                }

            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        synchronized (ProgressBar.class) {
            int val =++ProgressBar.threadCount;
            if(val == 10)
            {
                                System.out.println("All threads are finished!") ;
            }
        }

    }
}

I’ve been testing for 5mins now, and it seems to work.
But can someone explain what’s happening? When a thread is started, it makes sure that the synchronized block is not in use, otherwise it waits for it to be completed.
So is it some queueing system?
Thanks again.
EDIT:

Previous links
How does AtomicInteger work?

Thread.join freezes progressbar

  • 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-26T22:05:26+00:00Added an answer on May 26, 2026 at 10:05 pm

    A synchronized block uses the lock in the object that it refers to, in your case ProgressBar.class. If no other thread owns the lock, the synchronized block acquires it and proceeds. If the lock already is owned by another thread, the synchronized block goes to sleep to await the release of the lock, at which point it tries again. Once the thread that owns the lock finishes with the synchronized block, it releases the lock, which causes at least one of the threads that are waiting for the lock to attempt to acquire it.

    (This explanation overlooks the possibility that the same thread may acquire a lock several times before releasing it. So long as the thread owns the lock at least once, all other threads are blocked from acquiring it.)

    See the Java Language Specification.

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

Sidebar

Related Questions

I really don't like this style of formatting: Class AwesomeClass { private static void
I have this problem and really don't know how to solve this. I'm having
I really don't understand Javascript. In PHP, I can remove quotes like this: $tags_array
I really don't think this is a precision problem, the answer should be about
I really don't like the VS2008 Start Page. I don't need the RSS reader,
As a developer I really don't like writing documentation but when I have to
I am re-designing an application for a ASP.NET CMS that I really don't like.
I really don't like the concept of opening my SQL server(s) to the internet
I really don't want to have to reinvent the wheel with this one. There
I really don't understand what I'm doing wrong, but according to Adobe, this is

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.