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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:41:53+00:00 2026-06-18T23:41:53+00:00

I create new Thread and start it. It’s run method has following code: for

  • 0

I create new Thread and start it. It’s run method has following code:

for (int a=0; a<10; a++) {
    System.out.println(a);
    Thread.sleep(10);
}

And what I get is:

0
0
1
1
2
0
2
3
1
0
3
4
2
1
0
4
5
3
2
1
0
5
6
4

… and so on. Why I don’t get 1 2 3 4 5 6 7 8 9 ? What’s the reason?

EDIT:

Thread code:

private class WarpEnemyRnn implements Runnable {
    private WarpEnemy enemy;

    public WarpEnemyRnn(WarpEnemy enemy) {
        this.enemy = enemy;
    }

    @Override
    public void run() {
        try {
            for (int a=0; a<8; a++) {
                System.out.println(a);
                enemy.subOpacity();
                Thread.sleep(refreshRate);
            }
            Point2D warpPoint = enemy.warp();
            enemy.setX((int) warpPoint.getX());
            enemy.setY((int) warpPoint.getY());
            enemy.resetWarpCooldown();
            for (int a=0; a<8; a++) {
                enemy.addOpacity();
                Thread.sleep(refreshRate);
            }
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
}

New thread is created in other thread which runs every 15ms. It’s created only when some condition agrees.

  • 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-18T23:41:54+00:00Added an answer on June 18, 2026 at 11:41 pm

    All threads print to the same standard output.

    Every time you see a 0 printed out is when a new thread is created.

    Here are your threads:

    0   1   2     3       4         5           6  
      0   1     2       3         4           5    
              0     1       2         3           4
                      0       1         2
                                0         1
                                            0
    

    Each is printing the numbers in sequence.

    Note – It’s not guaranteed for each output to be assigned to the thread I specified, this is just one possible alignment of outputs (e.g. the output of the the first two threads are interchangeable), but the timing suggests that this is indeed the correct assignment.

    You could add a unique ID to each thread if you want to see which thread prints what.

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

Sidebar

Related Questions

Error: java.lang.OutOfMemoryError: unable to create new native thread java.lang.Thread.start0(Native Method) java.lang.Thread.start(Unknown Source) java.util.Timer.<init>(Unknown Source)
I have the following code: var x = new Thread(new ThreadStart(Delegate)); x.Start(); This will
I'm trying to create a new System.Threading.Thread object using Jscript, but I can't get
Hy! My code: Thread thread = new Thread (){ @Override public void run() {
What would be difference between the following approach? Task.Factory.StartNew(() => CustomConnection()); new Thread(CustomConnection).Start(); Both
In my application, I create a new UI-Thread with the fallowing code: Thread thread
thread = new Thread() { @Override public void run() { while(!requestedToExit) { SystemClock.sleep(3000); Log.d(debug,
For Create And Start New Threads In C# We Act Like Below : using
Ok , I know the two standard ways to create a new thread and
Often I create Child threads within the main() as Thread thread = new Thread(new

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.