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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:34:19+00:00 2026-05-27T15:34:19+00:00

Say I run a simple single-threaded process like the one below: public class SirCountALot

  • 0

Say I run a simple single-threaded process like the one below:

public class SirCountALot {
    public static void main(String[] args) {
        int count = 0;
        while (true) {
            count++;
        }
    }
}

(This is Java because that’s what I’m familiar with, but I suspect it doesn’t really matter)

I have an i7 processor (4 cores, or 8 counting hyperthreading), and I’m running Windows 7 64-bit so I fired up Sysinternals Process Explorer to look at the CPU usage, and as expected I see it is using around 20% of all available CPU.

Graph showing 20% CPU usage across all cores

But when I toggle the option to show 1 graph per CPU, I see that instead of 1 of the 4 “cores” being used, the CPU usage is spread all over the cores:

Graph showing erratic CPU usage on each core totaling around 20% usage

Instead what I would expect is 1 core maxed out, but this only happens when I set the affinity for the process to a single core.

Graph showing most of recent CPU usage to be confined to first core

Why is the workload split over the separate cores? Wouldn’t splitting the workload over several cores mess with the caching or incur other performance penalties?

Is it for the simple reason of preventing overheating of one core? Or is there some deeper reason?

Edit: I’m aware that the operating system is responsible for the scheduling, but I want to know why it “bothers”. Surely from a naive viewpoint, sticking a (mostly*) single-threaded process to 1 core is the simpler & more efficient way to go?

*I say mostly single-threaded because there’s multiple theads here, but only 2 of them are doing anything:

Screenshot showing number of threads from Eclipse
Screenshot showing number of threads in Process Explorer process properties

  • 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-05-27T15:34:19+00:00Added an answer on May 27, 2026 at 3:34 pm

    The OS is responsible for scheduling. It is free to stop a thread and start it again on another CPU. It will do this even if there is nothing else the machine is doing.

    The process is moved around the CPUs because the OS doesn’t assume there is any reason to continue running the thread on the same CPU each time.

    For this reason I have written a library for lock threads to a CPU so it won’t move around and won’t be interrupted by other threads. This reduces latency and improve throughput but does tire up a CPU for that thread. This works for Linux, perhaps you can adapt it for Windows. https://github.com/peter-lawrey/Java-Thread-Affinity/wiki/Getting-started

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

Sidebar

Related Questions

Say I've got something like this public void run(){ Thread behaviourThread = new Thread(abstractBehaviours[i]);
Let's say that I have the following code that's run in one thread of
For a simple rails application ( 1.86 /2.3.5) , lets say I run a
I have a simple script say test.sh something like this: #!/bin/sh for i in
Fist of all, when I say run a desktop app within a applet I
In another discussion , someone say something about run the java code on its
Say that you're developing code which needs to compile and run on multiple hosts
Let's say I want to run a .NET application on a machine where the
Say, I love Debian+mod_rails and run it on my laptop which is my development
Say you have a large PHP project and suddenly, when attempting to run 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.