0

My System is 7 core CPU machine. I just tried running the below program

 for(int i=0;i<10; i++)
 {
        new Thread(new Runnable()
        {   
            @Override
            public void run()
            {
                while (true)
                {

                }   
            }
        }).start();;
    }

Now my full CPU usage is 100%(7 cores are 100%). Here 10 threads are in single Process javaw.exe. How it got split across all of my CPU cores?

Whether a single process can run in multiple cores or whether java implementation take care of giving threads across different processors?

Sangeeth
  • 614
  • 1
  • 5
  • 14

1 Answers1

1

Yes, multiple threads of the same process can be split across multiple CPU. For many applications, that is the whole point of using multiple threads.

Most current JVM implementations use native OS threads for this (one Java thread - one OS thread), so this is all done by the operating system. The alternative would be "green threads" where the JVM would manually schedule execution. This seems to be a thing of the past, for architectures or OS without "real" threads.

Community
  • 1
  • 1
Thilo
  • 257,207
  • 101
  • 511
  • 656