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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:13:35+00:00 2026-06-09T00:13:35+00:00

When I run the below code which is an example of multithreading using java

  • 0

When I run the below code which is an example of multithreading using java netbeans compiler my pc hangs.
Why does this happen?

class clicker implements Runnable
{
  int click=0;
  Thread t;
  private volatile boolean runn=true;
  public clicker(int p)
  {
    t=new Thread(this);
    t.setPriority(p);
  }
  public void run()
  {
    while(runn)
      click++;
  }
  public void stop()
  {
    runn=false;
  }
  public void start()
  {
    t.start();
  }
}
public class Hilopri
{
  public static void main(String args[])
  {
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    clicker hi=new clicker(Thread.NORM_PRIORITY+2);
    clicker low=new clicker(Thread.NORM_PRIORITY-2);
    low.start();
    hi.start();
    try
    {
      Thread.sleep(500);
    }
    catch(Exception e)
    {
      low.stop();
      hi.stop();
    }
    try
    {
      hi.t.join();
      low.t.join();
    }
    catch(Exception e)
    {
      System.out.println(e);
    }
    System.out.println("Low"+low.click);
    System.out.println("High"+hi.click);
  }
}
  • 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-09T00:13:37+00:00Added an answer on June 9, 2026 at 12:13 am

    It’s because you call low.stop() and hi.stop() in the catch block which is only executed if Thread.sleep(500) throws an exception <=> is interrupted. And nothing in your code interrupts it.

    You probably meant to put the stop calls in a finally block:

        try {
            Thread.sleep(500);
        } catch (Exception e) {
        } finally {
            low.stop();
            hi.stop();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I get this error when I run the code below. I have normally used
for example, if i run the code below, $ProgramName is a string not a
Below is some example code of how I run my mysql queries, I run
Currently I am using the below code to start my application (which is working)
When I run below code, it's giving a message that: the application stopped unexcepctedlly
When i run the below code I am getting error like ex = {The
When I run the below code, everything goes great until I change the value
I'm trying to run the below-mentioned code in VB(Excel Macro) but I'm stuck with
I tried below code but as I run it gives a black screen image
When I run the code below NSString *chemin; chemin = [NSString stringWithFormat:@chapitre0%d, [sender tag]];

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.