I've just started programming in Java, and I'm interested in how computers distribute their CPU load. I have made a very basic program that creates a window and makes a box and line move. While testing this, I looked at Task Manager; Task manager said I was using ~1% of my CPUs. however, when I ran my program, the CPU usage went up to ~36% (I only started the program, nothing else). Can anyone tell me what is going on here, please?
Asked
Active
Viewed 281 times
2
-
1"...interested in how computers distribute CPU load." Computers don't. Operating Systems do. What you are interested in is called "scheduling" An operating system's _scheduling algorithm_ decides which thread gets to run, and on what processor. http://en.wikipedia.org/wiki/Scheduling_%28computing%29 – Solomon Slow Feb 24 '15 at 21:33
1 Answers
5
You think that your program has only one thread, but in reality every Java program has lots of threads. GUI apps have the Event Dispatch Thread, garbage collection has its own thread etc. You can use a profiler (like the VisualVM that is in the JDK) to see all the threads in your app.
Or you can see them programmatically, see Get a List of all Threads currently running in Java