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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:18:54+00:00 2026-06-15T13:18:54+00:00

I am trying to run two different threads at a time, but unable to

  • 0

I am trying to run two different threads at a time, but unable to do that. Thread_1 & Thread_2 runs, but difference between them is around 500ms. I am not using wait() or sleep() anywhere in my code.

Questions:

  1. How to make run thread simultaneously or in parallel?

  2. How to make thread run fast?

For second question this I used Thread.setPriority(Thread.MAX_PRIORITY) but time difference between other is same.

Updated with example code

Doing same as below example, but takes more time between both threads to run.

public static void main(String args[])
{
    MyThread thread1 = new MyThread("thread1: ");
    MyThread thread2 = new MyThread("thread2: ");
    thread1.start();
    thread2.start();
    boolean thread1IsAlive = true;
    boolean thread2IsAlive = true;
    do {
       if (thread1IsAlive && !thread1.isAlive()) {
           thread1IsAlive = false;
            System.out.println("Thread 1 is dead.");
       }
       if (thread2IsAlive && !thread2.isAlive()) {
           thread2IsAlive = false;
           System.out.println("Thread 2 is dead.");
       }
    } while(thread1IsAlive || thread2IsAlive);
}

I have searched the web and gone through some docs. What can I try next?

  • 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-15T13:18:56+00:00Added an answer on June 15, 2026 at 1:18 pm

    How to make run thread simultaneously or in parallel?

    As a programmer it’s only possible on multi processor machines. On single processor only one thread will run at one time and it’s upto JVM (and OS) to choose which thread to run.

    How to make thread run fast ?

    You can try (as you did), but overall control is with JVM (and OS) only.

    However, increasing the priority of thread doesn’t mean that it’ll run fast. it only makes chances for the thread to run more frequently than other threads. i.e. OS may (or may not)choose it more no. of times than other threads.

    Go through this link for some more details. Check this too.

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

Sidebar

Related Questions

I want to write an App, that can run two different threads, one for
I have two very similar programs each trying to run two threads OddThread and
I am trying to run two separate threads, like A and B. A and
I am trying to profile two different queries that do the same thing to
I am trying to run two different jQuery/Java Scripts under one file name... And
I'm trying to run two different sets of functions, based on whether or not
I am trying to run my Expect script from two different locations and it
I have two test cases (two different files) that I want to run together
I am trying to run two scripts: one for loading page content using ajax
I am trying a run an image magick commands which spans overs two lines

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.