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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:44:15+00:00 2026-06-16T07:44:15+00:00

I have a function that creates several threads.For each thread,a constructor takes an object

  • 0

I have a function that creates several threads.For each thread,a constructor takes an object from a different class, so I have first to create an object of this class and then create the thread. Below the code(modified for the simplification of example)

public static void createThread (int n) {
      for(int i=0;i<n;i++){
         someClass obj=new someClass(i);
         ThreadClass myThread=new ThreadClass(obj);
         myThread.run();
        }

The problem here is that I don’t really see that threads are running randomly. I am printing each one of them on run() and I see that they are displayed in their order. Is anything wrong with this? Should I run it differently?

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-16T07:44:17+00:00Added an answer on June 16, 2026 at 7:44 am

    Use Thread.start() rather than Thread.run(). Using the run method simply calls that method in the same thread, whereas the start method actually creates a new thread and calls the run method within that thread.

    I assume by “randomly”, you actually mean interleaving. This should lead to that result.

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

Sidebar

Related Questions

I have a Parallel foreach function that creates a new instance of a class,
Say I have a function func(i) that creates an object for an integer i,
I have the following function that takes a number like 5 and creates a
I have a main thread that creates a form object which creates and sets
My program have several worker threads that calling a function in a dynamically loaded
I have a function that creates time intervals between two time marks. The function
I have a function that creates zip files when passed an array of files
I have a function that creates a course. I am trying to get the
I have a function that creates a 2D vector void generate(int n) { vector<
I have a Matlab function that creates a cell array with matrixes inside. It

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.