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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:16:31+00:00 2026-06-10T05:16:31+00:00

Here is my code public class ThreadLearn{ private static class Check implements Runnable{ public

  • 0

Here is my code

public class ThreadLearn{
private static class Check implements Runnable{
    public void run(){

        System.out.printf("\nInCheck %s", Thread.currentThread().getName());
    }
}

public static void main(String[] args){

   Thread t;
   int i=0;
   while(i<2){
      t = new Thread(new GetData());
      t.start();
      System.out.printf("\n%s: ", t.getName());
      i++;
   }

}

}

The output is:

InRun Thread-0
Thread-0:
Thread-1:
InRun Thread-1

I have two questions:

  1. Should not the output be

    InRun Thread-0

    Thread-0:

    InRun Thread-1

    Thread-1:

  2. Once the t.start() is done, will it wait for the run() to be executed and then create the second thread? what if i want to do the following

    while(required)

    new Thread().start();

and in my run method i can have all the stuff that i want the threads to accomplish in parallel so that it doesnt wait for one thread to complete the run method and then create the second thread.

Thanks

  • 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-10T05:16:32+00:00Added an answer on June 10, 2026 at 5:16 am

    Should not the output be …

    No. Threads run independently of each other. The JVM and operating system decide when which thread is running. In general, the order in which two threads are executed is unpredictable. It could very well happen that when you run the program again, the result is different.

    Once the t.start() is done, will it wait for the run() to be executed and then create the second thread?

    No, it will not wait. The run() method of the new thread may start immediately, or later, depending on how threads are being scheduled.

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

Sidebar

Related Questions

Here's the code : public class EmployeeTest { public static void main(String args[]){ //System.out.println(hello
Here's my code public class Main { private static class GetData implements Runnable{ private
So here's my code : public class SetWritable<T extends Writable> implements Writable { private
Here is my code: public partial class Image : System.Web.UI.Page { protected void Page_Load(object
Here's my code: public class MyActivity extends Activity implements View.OnClickListener { private Button mHorizontalButton;
here is my code public class SimpleJoglApp extends JFrame { public static void main(String[]
Here is my code: public class Main { public static void main(String[] args) {
Here's my code: public class Game extends JComponent implements Runnable { World w =
Here is my code: public class Main { public static void main(String[] args) {
Here is some code: public class A { private volatile B b; public void

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.