So the STB is dual core. I thought we can only create 2 proper threads.
In every keyreleased()
I am creating a new thread
Runnable runnable = new Runnable()
{
int i = j;
public void run()
{
while (true)
{
System.out.println("This thread is running always number is " + i);
}
}
};
Thread th = new Thread(runnable);
th.setPriority(Thread.MAX_PRIORITY);
th.start();
j++;
//...
}
But even after creating 20 more threads, box doesn't have any issues.
Is it because JVM realized that the run block is empty and it optimized the code ? Or is the JVM implementation for while(true) is different ?
Note: i have tried putting Thread.sleep(1000) as well but no problems
You can run 20 threads even on a single-core machine. What happens is called time slicing.
http://en.wikipedia.org/wiki/Time_slice#Time_slice
It is a way for the processor to simulate multiple processors executing multiple tasks as once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With