My system Information says this
Processor Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz, 1992 Mhz, 4 Core(s), 8 Logical Processor(s)
So, I wrote 9 classes
and called all. Since there are only 4 core and 8 Logical Processor(s),
How all the nine functions printed parallelly?
Does it mean one core is handling two threads?
class Hi extends Thread {
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("Hi");
try {Thread.sleep(500);} catch (Exception e) {e.printStackTrace();}
}
}
}
class Hello extends Thread {
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("Hello");
try {Thread.sleep(500);} catch (Exception e) {e.printStackTrace();}
}
}
}
class Hello1 extends Thread {
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("Hello1");
try {Thread.sleep(500);} catch (Exception e) {e.printStackTrace();}
}
}
}
class Hello2 extends Thread {
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("Hello2");
try {Thread.sleep(500);} catch (Exception e) {e.printStackTrace();}
}
}
}
class Hello3 extends Thread {
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("Hello3");
try {Thread.sleep(500);} catch (Exception e) {e.printStackTrace();}
}
}
}
class Hello4 extends Thread {
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("Hello4");
try {Thread.sleep(500);} catch (Exception e) {e.printStackTrace();}
}
}
}
class Hello5 extends Thread {
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("Hello5");
try {Thread.sleep(500);} catch (Exception e) {e.printStackTrace();}
}
}
}
class Hello6 extends Thread {
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("Hello6");
try {Thread.sleep(500);} catch (Exception e) {e.printStackTrace();}
}
}
}
class Hello7 extends Thread {
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("Hello7");
try {Thread.sleep(500);} catch (Exception e) {e.printStackTrace();}
}
}
}
public class JavaThread_1 {
public static void main(String[] args) {
Hi hi = new Hi();
Hello hello = new Hello();
Hello1 hello1 = new Hello1();
Hello2 hello2= new Hello2();
Hello3 hello3 = new Hello3();
Hello4 hello4 = new Hello4();
Hello5 hello5 = new Hello5();
Hello6 hello6 = new Hello6();
Hello7 hello7 = new Hello7();
hi.start();
hello.start();
hello1.start();
hello2.start();
hello3.start();
hello4.start();
hello5.start();
hello6.start();
hello7.start();
}
}
output
Hi
Hello3
Hello2
Hello1
Hello
Hello5
Hello4
Hello6
Hello7
..
...
.... same thing continues for every 500 ms but how 9 threads executed simultaneously I'm not getting