Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Why Child Threads do not work when using while(true) loop in main thread without sleep?

  1. #1
    Junior Member
    Join Date
    Jul 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why Child Threads do not work when using while(true) loop in main thread without sleep?

    When using while(true) loop in main thread with Thread.sleep() the child threads works fine but if i remove sleep method from while loop the child threads do not work. I mean, thread defines parallelism so it should work ?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    23,186
    Thanks
    53
    Thanked 2,465 Times in 2,416 Posts

    Default Re: Why Child Threads do not work when using while(true) loop in main thread without sleep?

    child threads do not work.
    Please explain what "do not work" means.
    Using sleep in one thread would allow another thread to have more use of a CPU.
    It is up to the OS to decide which thread gets to execute. If a thread is executing and does not do anything to pause its execution, it can continue executing for a while.

    How many cores/cpus does your PC have?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Alternative to thread.sleep?
    By jm24 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 12th, 2012, 01:42 AM
  2. Threads are killed randomly in While true loop
    By kurt-hardy in forum Threads
    Replies: 7
    Last Post: August 11th, 2011, 07:55 AM
  3. Problem with thread.sleep()
    By stormforce in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 19th, 2011, 02:10 AM
  4. [SOLVED] Giving Thread.sleep( ); a decimal value
    By Knox in forum Threads
    Replies: 2
    Last Post: April 9th, 2011, 08:55 PM
  5. [SOLVED] Thread.sleep() in while loop not working
    By mds1256 in forum Threads
    Replies: 4
    Last Post: January 13th, 2011, 06:02 AM

Tags for this Thread