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

  • Home
  • SEARCH
  • 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 4035262
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:04:33+00:00 2026-05-20T12:04:33+00:00

Recently I learned CyclicBarrier, but here’s a question: Code: public class Main { public

  • 0

Recently I learned CyclicBarrier, but here’s a question:

Code:

public class Main {
    public static CyclicBarrier c;

    public static void main(String[] agrs){
        int threadsCount = 5;
        c = new CyclicBarrier(threadsCount + 1);
        // make 5 A threads to run
    }
}

public class A implements Runnable {

    public void run(){
        // do something
       Main.c.await();
        // do something
    }
}

In about code, I wonder that why I must initialize CyclicBarrier by (threadsCount + 1) but not (threadsCount), since I never invoke await() in the main method?

  • 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-20T12:04:33+00:00Added an answer on May 20, 2026 at 12:04 pm

    n is the number of parties where new CyclicBarrier(n) creates a new CyclicBarrier that will trip when the given number of parties (threads) are waiting upon it, and does not perform a predefined action upon each barrier.

    I would posit that the origin thread is counted as accessing the barrier, thus when you create 5 new threads, if you didn’t wait on 5+1 threads then you’d trip before you were ready.

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

Sidebar

Related Questions

Having recently learned Grand Central Dispatch, I've found multithreaded code to be pretty intuitive(with
I recently learned about endianness and am still having difficulty identifying problem areas. Here
I have recently learned, that in MATLAB, the ! mark runs the code in
I recently learned that Unicode is permitted within Java source code not only as
I recently learned about code obfuscation. Its nice thing to do, when you have
I've recently learned that i shouldn't store html encoded data in the database, but
I recently learned about the basic structure of the .docx file (it's a specially
I have recently learned the Ruby programming language, and all in all it is
Having recently learned of the DebuggerDisplay attribute, I've found it quite useful. However, one
I recently learned of the IIF(A,B,C) function. I'm a long time VB/VB.NET Coder who

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.