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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:41:01+00:00 2026-05-23T11:41:01+00:00

In most of the threading examples in Java, there is common use of a

  • 0

In most of the threading examples in Java, there is common use of a while(true) block like this:

while(true) {
 try {
  wait() 
 } catch (Exception ex) {
   /*do  something*/ 
 }
}

What is the purpose of using while (true) ? Under what kind of scenarios are they particularly useful?
Client/Server communications?

Thanks,
– Ivar

  • 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-23T11:41:01+00:00Added an answer on May 23, 2026 at 11:41 am

    while(true) is useful if you want to do something all the time while your code is running and you don’t know how often you have to do it.

    Client/Server Communication is one scenario. Other scenarios are animations of games or keeping some values always up to date.

    A Thread is seperated from the other code, so your application would not hang by using while(true).

    It is usefull to add an exit-flag to your while(true)-loop, so you can stop it if you want to.

    Boolean isExit = false; //set this value to true when needed.
    while(true) {
     try {
      if(isExist){
        break;
      }
      wait() 
     } catch (Exception ex) {
       /*do  something*/ 
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Most of the implementations I find require a hardware instruction to do this. However
Most of our Eclipse projects have multiple source folders, for example: src/main/java src/test/java When
This question is related to my question on existing coroutine implementations in Java .
I am trying to learn how to use threads with python. this is the
It seems I figured out most of my problems by simply multi-threading my application!
I'm trying to come up with some programming puzzles focused on multi-threading. Most of
The Java Tutorials listed a couple of books for further reading regarding threading /
Interlocked.Increment seems like among the most standard/simple of operations one would need to perform
I would like to share data between the objects. Actually, for example, there is
Though standard doesn't guarantee the thread-safety for new , most of the multi-threading operating

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.